Boundingbox Size of Point selection
-
On 21/12/2015 at 02:34, xxxxxxxx wrote:
Hi, I am trying to get the Size of a Pointselection...basically what obj.GetRad() is for Objectsize...but for selected Points.
Is there an easy way?
-
On 21/12/2015 at 03:28, xxxxxxxx wrote:
The easy way is to calculate it. It's simple for a given set of points. Just make sure you use a copy of
the starting point, otherwise you'll have two times the same vector and that will lead to wrong results.minv = c4d.Vector(points[0]) maxv = c4d.Vector(points[0])
-
On 21/12/2015 at 03:35, xxxxxxxx wrote:
I tried this...whats not working here?
def GetSelectionSize(op) : sel = op.GetPointS() points = [(i, point) for i, point in enumerate(op.GetAllPoints()) if sel.IsSelected(i)] if not points: return selsizemin = min(c4d.Vector(point[1]) for point in points) selsizemax = max(c4d.Vector(point[1]) for point in points) selsize= selsizemax-selsizemin return selsize
-
On 21/12/2015 at 04:10, xxxxxxxx wrote:
You have to find the min/max for each **component (x, y, z) **of all points, not the min/max of all points.
-
On 21/12/2015 at 04:11, xxxxxxxx wrote:
Also, why do you write point[1] ? That'll give you the Y component of the Vector.
-
On 21/12/2015 at 04:11, xxxxxxxx wrote:
I guess you are right
-
On 21/12/2015 at 04:56, xxxxxxxx wrote:
This Works now. I guess its more complicated than it could be
def GetSelectionSize(op) : sel = op.GetPointS() points = [(i, point) for i, point in enumerate(op.GetAllPoints()) if sel.IsSelected(i)] if not points: return selsizeminX = min(point[1].x for point in points) selsizemaxX = max(point[1].x for point in points) selsizeminY = min(point[1].y for point in points) selsizemaxY = max(point[1].y for point in points) selsizeminZ = min(point[1].z for point in points) selsizemaxZ = max(point[1].z for point in points) boundbox= c4d.Vector(selsizemaxX,selsizemaxY,selsizemaxZ)-c4d.Vector(selsizeminX,selsizeminY,selsizeminZ) selsize=boundbox.GetLength() return selsize
-
On 21/12/2015 at 05:00, xxxxxxxx wrote:
Just a question, because Im instrested in: Wouldnt it be better to do all in one for-loop?
-
On 21/12/2015 at 06:05, xxxxxxxx wrote:
I tried it out. Im not sure if its the best practice, but the results.
import c4d from datetime import datetime #Welcome to the world of Python class stopwatch() : def __init__(self) : start = datetime.now() def start(self) : self.start = datetime.now() return self.start def stop(self) : return datetime.now()-self.start def GetSelectionSize(op) : sel = op.GetPointS() points = [(i, point)for i, point in enumerate(op.GetAllPoints())if sel.IsSelected(i)] if not points: return selsizeminX = min(point[1].x for point in points) selsizemaxX = max(point[1].x for point in points) selsizeminY = min(point[1].y for point in points) selsizemaxY = max(point[1].y for point in points) selsizeminZ = min(point[1].z for point in points) selsizemaxZ = max(point[1].z for point in points) boundbox = c4d.Vector(selsizemaxX,selsizemaxY,selsizemaxZ)-c4d.Vector(selsizeminX,selsizeminY,selsizeminZ) selsize = boundbox.GetLength() return selsize def GetSelectionSize2(obj) : v_min = None v_max = None for i, sel in enumerate(obj.GetPointS().GetAll(obj.GetPointCount())) : if sel: p = obj.GetPoint(i) if v_min == None: v_min = c4d.Vector(p.x, p.y, p.z) if v_max == None: v_max = c4d.Vector(p.x, p.y, p.z) v_min.x = min(v_min.x, p.x) v_min.y = min(v_min.y, p.y) v_min.z = min(v_min.z, p.z) v_max.x = max(v_max.x, p.x) v_max.y = max(v_max.y, p.y) v_max.z = max(v_max.z, p.z) boundbox = v_max - v_min selsize = boundbox.GetLength() return selsize def main() : obj = op.GetDown() t1 = stopwatch() t1.start() size = GetSelectionSize(obj) print t1.stop() print size t1 = stopwatch() t1.start() size = GetSelectionSize2(obj) print t1.stop() print size return None
Pointcount 600.001 and 300.000 selected:
GetSelectionSize(obj) : 0.022sec.
GetSelectionSize2(obj) : 0.017sec.Pointcount 1.500.001 and 750.000 selected:
GetSelectionSize(obj) : 0.469sec.
GetSelectionSize2(obj) : 0.137sec.