第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

由角點(diǎn)定義的邊界框?qū)ο蟮那短讓傩?/h1>

通常,攪拌器腳本必須從 3D 點(diǎn)集合計(jì)算包圍邊界框,例如將默認(rèn)攪拌器立方體邊界框作為輸入,coords = np.array(     [[-1.  1. -1.],      [-1.  1.  1.],      [ 1. -1. -1.],      [ 1. -1.  1.],      [ 1.  1. -1.],      [ 1.  1.  1.]] )bfl = coords.min(axis=0)tbr = coords.max(axis=0)G  = np.array((bfl, tbr)).Tbbox_coords = [i for i in itertools.product(*G)]例如,邊界框坐標(biāo)將是相同順序的立方體坐標(biāo)尋找一些Python“迭代魔法”,使用上面的和("left", "right"), ("front", "back"),("top", "bottom"),來(lái)制作一個(gè)輔助類(lèi)>>> bbox = BBox(bfl, tbr)>>> bbox.bottom.front.left(-1, -1, -1)>>> bbox.top.front(0, -1, 1)>> bbox.bottom(0, 0, -1)即角頂點(diǎn)、邊的中心、矩形的中心。(1、2 或 4 個(gè)角的平均總和)在攪拌機(jī)中,頂部為 +Z,前面為 -Y。最初是在考慮用靜態(tài)計(jì)算值填充嵌套字典之類(lèi)的東西d = {    "front" : {        "co" : (0, -1, 0),        "top" : {            "co" : (0, -1, 1),            "left" : {"co" : (-1, -1, 1)},            }        }       }通常,攪拌器腳本必須從 3D 點(diǎn)集合計(jì)算包圍邊界框,例如將默認(rèn)攪拌器立方體邊界框作為輸入,coords = np.array(     [[-1.  1. -1.],      [-1.  1.  1.],      [ 1. -1. -1.],      [ 1. -1.  1.],      [ 1.  1. -1.],      [ 1.  1.  1.]] )bfl = coords.min(axis=0)tbr = coords.max(axis=0)G  = np.array((bfl, tbr)).Tbbox_coords = [i for i in itertools.product(*G)]例如,邊界框坐標(biāo)將是相同順序的立方體坐標(biāo)尋找一些Python“迭代魔法”,使用上面的和("left", "right"), ("front", "back"),("top", "bottom"),來(lái)制作一個(gè)輔助類(lèi)>>> bbox = BBox(bfl, tbr)>>> bbox.bottom.front.left(-1, -1, -1)>>> bbox.top.front(0, -1, 1)>> bbox.bottom(0, 0, -1)即角頂點(diǎn)、邊的中心、矩形的中心。(1、2 或 4 個(gè)角的平均總和)在攪拌機(jī)中,頂部為 +Z,前面為 -Y。最初是在考慮用靜態(tài)計(jì)算值填充嵌套字典之類(lèi)的東西d = {    "front" : {        "co" : (0, -1, 0),        "top" : {            "co" : (0, -1, 1),            "left" : {"co" : (-1, -1, 1)},            }        }       }
查看完整描述

3 回答

?
牧羊人nacy

TA貢獻(xiàn)1862條經(jīng)驗(yàn) 獲得超7個(gè)贊

這是兩個(gè)相似的版本。兩者的想法都是,您始終返回一個(gè)BBox對(duì)象,并且僅更改一個(gè)變量x ,該變量指示您通過(guò)left, , ... 指定的尺寸。最后,您有一個(gè)用于計(jì)算剩余角的中心的right函數(shù)。x


第一種方法使用函數(shù),因此您必須調(diào)用它們bbox.bottom().front().left().c()。這里的主要區(qū)別在于并非所有組合


top

top left

top right

top left front

...

在創(chuàng)建對(duì)象時(shí)計(jì)算,但僅在調(diào)用它們時(shí)計(jì)算。



import numpy as np

import itertools


class BBox:

    """

    ("left", "right"), -x, +x

    ("front", "back"), -y, +y

    ("bottom", "top"), -z, +z

    """

    def __init__(self, bfl, tbr):

        self.bfl = bfl

        self.tbr = tbr


        self.g = np.array((bfl, tbr)).T


        self.x = [[0, 1], [0, 1], [0, 1]]


    def c(self):  # get center coordinates

        return np.mean([i for i in itertools.product(*[self.g[i][self.x[i]] for i in range(3)])], axis=0)


    def part(self, i, xi):

        assert len(self.x[i]) == 2

        b2 = BBox(bfl=self.bfl, tbr=self.tbr)

        b2.x = self.x.copy()

        b2.x[i] = [xi]

        return b2


    def left(self):

        return self.part(i=0, xi=0)


    def right(self):

        return self.part(i=0, xi=1)


    def front(self):

        return self.part(i=1, xi=0)


    def back(self):

        return self.part(i=1, xi=1)


    def bottom(self):

        return self.part(i=2, xi=0)


    def top(self):

        return self.part(i=2, xi=1)



bbox = BBox(bfl=[-1, -1, -1], tbr=[1, 1, 1])

>>> bbox.bottom().front().left().c()

(-1, -1, -1)


>>> bbox.top().front().c()

(0, -1, 1)


>>> bbox.bottom().c()

(0, 0, -1)

第二種方法使用本身就是BBox對(duì)象的屬性。當(dāng)您取消注釋函數(shù)中的 print 語(yǔ)句時(shí),init您可以了解構(gòu)造過(guò)程中發(fā)生的所有遞歸調(diào)用。因此,雖然查看這里發(fā)生的情況可能會(huì)更復(fù)雜,但訪(fǎng)問(wèn)屬性時(shí)會(huì)更方便。


class BBox:

    def __init__(self, bfl, tbr, x=None):

        self.bfl = bfl

        self.tbr = tbr

        self.g = np.array((bfl, tbr)).T


        self.x = [[0, 1], [0, 1], [0, 1]] if x is None else x

        

        # print(self.x)  # Debugging 

        self.left = self.part(i=0, xi=0)

        self.right = self.part(i=0, xi=1)

        self.front = self.part(i=1, xi=0)

        self.back = self.part(i=1, xi=1)

        self.bottom = self.part(i=2, xi=0)

        self.top = self.part(i=2, xi=1)


    def c(self):  # get center coordinates

        return np.mean([i for i in itertools.product(*[self.g[i][self.x[i]] 

                        for i in range(3)])], axis=0)


    def part(self, i, xi):

        if len(self.x[i]) < 2:

            return None

        x2 = self.x.copy()

        x2[i] = [xi]

        return BBox(bfl=self.bfl, tbr=self.tbr, x=x2)


bbox = BBox(bfl=[-1, -1, -1], tbr=[1, 1, 1])

>>> bbox.bottom.front.left.c()

(-1, -1, -1)

您還可以在構(gòu)造函數(shù)的末尾添加類(lèi)似的內(nèi)容,以刪除無(wú)效的屬性。(以防止類(lèi)似的事情bbox.right.left.c())。它們None以前是,但AttributeError可能更合適。


   def __init__(self, bfl, tbr, x=None):

       ...

       for name in ['left', 'right', 'front', 'back', 'bottom', 'top']:

           if getattr(self, name) is None:

               delattr(self, name)

你也可以添加一個(gè)__repr__()方法:


    def __repr__(self):

        return repr(self.get_vertices())


    def get_vertices(self):

        return [i for i in itertools.product(*[self.g[i][self.x[i]]

                                               for i in range(3)])]


    def c(self):  # get center coordinates

        return np.mean(self.get_vertices(), axis=0)



bbox.left.front

# [(-1, -1, -1), (-1, -1, 1)]

bbox.left.front.c()

# array([-1., -1.,  0.])

編輯

一段時(shí)間后回到這個(gè)問(wèn)題后,我認(rèn)為最好只添加相關(guān)屬性而不添加全部,然后刪除其中一半。所以我能想到的最緊湊/最方便的類(lèi)是:


class BBox:

    def __init__(self, bfl, tbr, x=None):

        self.bfl, self.tbr = bfl, tbr

        self.g = np.array((bfl, tbr)).T

        self.x = [[0, 1], [0, 1], [0, 1]] if x is None else x


        for j, name in enumerate(['left', 'right', 'front', 'back', 'bottom', 'top']):

            temp = self.part(i=j//2, xi=j%2)

            if temp is not None:

                setattr(self, name, temp)


    def c(self):  # get center coordinates

        return np.mean([x for x in itertools.product(*[self.g[i][self.x[i]]

                                                       for i in range(3)])], axis=0)


    def part(self, i, xi):

        if len(self.x[i]) == 2:

            x2, x2[i] = self.x.copy(), [xi]

            return BBox(bfl=self.bfl, tbr=self.tbr, x=x2)


查看完整回答
反對(duì) 回復(fù) 2023-09-12
?
一只斗牛犬

TA貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超2個(gè)贊

這是使用迭代方法創(chuàng)建字典的另一個(gè)解決方案:


import numpy 

import itertools


directions = ['left', 'right', 'front', 'back', 'bottom', 'top']

dims = np.array([  0,       0,       1,      1,        2,     2])  # xyz


def get_vertices(bfl, tbr, x):

    g = np.array((bfl, tbr)).T

    return [v for v in itertools.product(*[g[ii][x[ii]] for ii in range(3)])]



bfl = [-1, -1, -1]

tbr = [1, 1, 1]


d = {}

for i in range(6):

    x = [[0, 1], [0, 1], [0, 1]]

    x[i//2] = [i % 2]  # x[dim[i] = min or max  

    d_i = dict(c=np.mean(get_vertices(bfl=bfl, tbr=tbr, x=x), axis=0))


    for j in np.nonzero(dims != dims[i])[0]:

        x[j//2] = [j % 2]

        d_ij = dict(c=np.mean(get_vertices(bfl=bfl, tbr=tbr, x=x), axis=0))


        for k in np.nonzero(np.logical_and(dims != dims[i], dims != dims[j]))[0]:

            x[k//2] = [k % 2]


            d_ij[directions[k]] = dict(c=np.mean(get_vertices(bfl=bfl, tbr=tbr, x=x), axis=0))

        d_i[directions[j]] = d_ij

    d[directions[i]] = d_i



d

# {'left': {'c': array([-1.,  0.,  0.]),

#    'front': {'c': array([-1., -1.,  0.]),

#      'bottom': {'c': array([-1., -1., -1.])},

#      'top': {'c': array([-1., -1.,  1.])}},

#    'back': {'c': array([-1.,  1.,  1.]),

#      'bottom': {'c': array([-1.,  1., -1.])},

#      'top': {'c': array([-1.,  1.,  1.])}}, 

#   ....

您可以將其與鏈接的問(wèn)題結(jié)合起來(lái),通過(guò) 訪(fǎng)問(wèn)字典的鍵d.key1.key2。


查看完整回答
反對(duì) 回復(fù) 2023-09-12
?
小怪獸愛(ài)吃肉

TA貢獻(xiàn)1852條經(jīng)驗(yàn) 獲得超1個(gè)贊

我到了哪里了。


以某種方式添加了這個(gè)作為答案,以更好地解釋我的問(wèn)題


循環(huán)遍歷立方體的 8 個(gè)頂點(diǎn),將 3 個(gè)名稱(chēng)與每個(gè)有效角相匹配。


“swizzle”是構(gòu)成角的三個(gè)軸方向的排列。


直接輸入自嵌套字典d[i][j][k] = value是創(chuàng)建它們的一種輕松方式。(pprint(d)下)


高興的是,從那里開(kāi)始,它變得丑陋,一些鴨子打字從簡(jiǎn)單的 8 垂直真值表中獲取元素索引。


沒(méi)有特殊原因,將返回生成類(lèi)的方法作為包裝器,但我沒(méi)有這樣使用它。


import numpy as np

import pprint

import operator

from itertools import product, permutations

from functools import reduce

from collections import defaultdict



class NestedDefaultDict(defaultdict):

    def __init__(self, *args, **kwargs):

        super(NestedDefaultDict, self).__init__(NestedDefaultDict, *args, **kwargs)


    def __repr__(self):

        return repr(dict(self))



def set_by_path(root, items, value):

    reduce(operator.getitem, items[:-1], root)[items[-1]] = value



def create_bbox_swizzle(cls, dirx=("left", "right"), diry=("front", "back"), dirz=("bottom", "top")):

    d = NestedDefaultDict()

    data = {}

    for i, cnr in enumerate(product(*(dirx, diry, dirz))):

        vert = {"index": i}

        data[frozenset(cnr)] = i

        for perm in permutations(cnr, 3):

            set_by_path(d, perm, vert)

    pprint.pprint(d)


    def wire_up(names, d):

        class Mbox:

            @property

            def co(self):

                return self.coords[self.vertices].mean(axis=0)

            def __init__(self, coords):

                self.coords = np.array(coords)

                self.vertices = [v for k, v in data.items() if k.issuperset(names)]

                pass


            def __repr__(self):

                if len(names) == 1:

                    return f"<BBFace {self.vertices}/>"

                elif len(names) == 2:

                    return f"<BBEdge {self.vertices}/>"

                elif len(names) == 3:

                    return f"<BBVert {self.vertices}/>"

                return "<BBox/>"

            pass


        def f(k, v):

            def g(self):

                return wire_up(names + [k], v)(self.coords)

            return property(g)


        for k, v in d.items():

            if isinstance(v, dict):

                setattr(Mbox, k, (f(k, v)))

            else:

                setattr(Mbox, k, v)

        return Mbox

    return wire_up([], d)



@create_bbox_swizzle

class BBox:

    def __init__(self, *coords, **kwargs):

        pass

試駕:


>>> bbox = BBox(coords)  # used coords instead of corners

>>> bbox.co

array([ 5.96046448e-08, -1.19209290e-07,  0.00000000e+00])


>>> bbox.left.bottom

<BBEdge [0, 2]/>


>>> bbox.left.bottom.vertices

[0, 2]


>>> bbox.left.bottom.co

array([-1.00000036e+00, -1.19209290e-07,  0.00000000e+00])


查看完整回答
反對(duì) 回復(fù) 2023-09-12
  • 3 回答
  • 0 關(guān)注
  • 134 瀏覽
慕課專(zhuān)欄
更多

添加回答

了解更多

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)