def test_pairs(self): pairs_points = Points.Points([ Card.Card(0, 1), Card.Card(0, 5), Card.Card(1, 5), Card.Card(0, 10) ], Card.Card(2, 10)) pairs_points.pairs() self.assertTrue(pairs_points.points == 4) pairs_points = Points.Points([ Card.Card(0, 13), Card.Card(0, 13), Card.Card(0, 13), Card.Card(0, 2) ], Card.Card(0, 10)) pairs_points.pairs() self.assertTrue(pairs_points.points == 6) pairs_points = Points.Points([ Card.Card(0, 10), Card.Card(0, 10), Card.Card(0, 10), Card.Card(0, 10) ], Card.Card(0, 1)) pairs_points.pairs() self.assertTrue(pairs_points.points == 12)
def test_runs(self): run_points = Points.Points([ Card.Card(0, 1), Card.Card(0, 1), Card.Card(0, 2), Card.Card(0, 3) ], Card.Card(0, 4)) run_points.runs() self.assertTrue(run_points.points == 8) run_points = Points.Points([ Card.Card(0, 9), Card.Card(0, 10), Card.Card(0, 10), Card.Card(0, 11) ], Card.Card(0, 3)) run_points.runs() self.assertTrue(run_points.points == 6) run_points = Points.Points([ Card.Card(0, 2), Card.Card(0, 3), Card.Card(0, 4), Card.Card(0, 5) ], Card.Card(0, 9)) run_points.runs() self.assertTrue(run_points.points == 4)
def test_fifteens(self): fifteens_points = Points.Points([ Card.Card(0, 1), Card.Card(0, 5), Card.Card(0, 5), Card.Card(0, 10) ], Card.Card(0, 10)) fifteens_points.fifteens(0, 0) self.assertTrue(fifteens_points.points == 8) fifteens_points = Points.Points([ Card.Card(0, 11), Card.Card(0, 12), Card.Card(0, 13), Card.Card(0, 5) ], Card.Card(0, 10)) fifteens_points.fifteens(0, 0) self.assertTrue(fifteens_points.points == 8) fifteens_points = Points.Points([ Card.Card(0, 8), Card.Card(0, 7), Card.Card(0, 9), Card.Card(0, 6) ], Card.Card(0, 10)) fifteens_points.fifteens(0, 0) self.assertTrue(fifteens_points.points == 4)
def test_nobs(self): nobs_points = Points.Points([ Card.Card(0, 2), Card.Card(1, 11), Card.Card(0, 4), Card.Card(0, 5) ], Card.Card(1, 9)) nobs_points.nobs() self.assertTrue(nobs_points.points == 1) nobs_points = Points.Points([ Card.Card(0, 2), Card.Card(1, 11), Card.Card(0, 4), Card.Card(2, 11) ], Card.Card(2, 9)) nobs_points.nobs() self.assertTrue(nobs_points.points == 1) nobs_points = Points.Points([ Card.Card(0, 2), Card.Card(2, 11), Card.Card(0, 4), Card.Card(0, 5) ], Card.Card(2, 9)) nobs_points.nobs() self.assertTrue(nobs_points.points == 1)
def run(pts, loop, d, dd, outliner=True): pts2 = np.array(pts) start = 0 pts3 = [] anzp = pts2.shape[0] for xp in range(120): # gesamtpunktzahl yv = 0 wv = 0 for i in range(anzp): x, y, z = pts2[i] if x < xp - d: start = i continue if x > xp + d: end = i break fak = 1 - abs(xp - x) / d wv += fak yv += fak * y if wv <> 0: yn = yv / wv else: continue if outliner: yv = 0 wv = 0 for i in range(start, end + 1): x, y, z = pts2[i] if abs(y - yn) > dd: print("outliner", loop, xp, i, y - yn) else: fak = 1 - abs(xp - x) / d wv += fak yv += fak * y if wv <> 0: yn = yv / wv pts3 += [FreeCAD.Vector(xp, yn, 0)] Points.show(Points.Points(pts3)) App.ActiveDocument.ActiveObject.ViewObject.ShapeColor = ( 0.5 + 0.5 * random.random(), 0.5 + 0.5 * random.random(), 0.5 + 0.5 * random.random()) pts4 = filter(lambda x: x[0] <= 100, pts3) ptsp = [ FreeCAD.Vector(p.y * np.cos(p.x * np.pi * 0.02), p.y * np.sin(p.x * np.pi * 0.02), 0) for p in pts4 ] Points.show(Points.Points(ptsp)) App.ActiveDocument.ActiveObject.ViewObject.ShapeColor = ( 0.5 + 0.5 * random.random(), 0.5 + 0.5 * random.random(), 0.5 + 0.5 * random.random()) return pts3, ptsp
def test_cards_only_rank(self): test_player1 = Player.Player("Player 1", False) test_player2 = Player.Player("Player 2", False) self.game = Game.Game(test_player1, test_player2) self.game.deal() self.game.top_card = self.game.deck.cut_deck() self.points1 = Points.Points(self.game.player1.hand.cards, self.game.top_card) self.points2 = Points.Points(self.game.player2.hand.cards, self.game.top_card) for card in self.points1.cards_only_rank: self.assertTrue(0 <= card <= 13) for card in self.points2.cards_only_rank: self.assertTrue(0 <= card <= 13)
def makeSurfaceFromSag(self, surface, startpoint=[0, 0, 0], R=50.0, rpoints=10, phipoints=12): # TODO: sdia parameter not valid anymore, change behaviour here, too. depending on the type of aperture surPoints = [] pts = Points.Points() pclpoints = [] for r in np.linspace(0, R, rpoints): points = [] for a in np.linspace(0.0, 360.0 - 360 / float(phipoints), phipoints): x = r * math.cos(a * math.pi / 180.0) # + startpoint[0] y = r * math.sin(a * math.pi / 180.0) # + startpoint[1] z = surface.shape.getSag(x, y) # + startpoint[2] p = FreeCAD.Base.Vector(x, y, z) p2 = FreeCAD.Base.Vector(x + startpoint[0], y + startpoint[1], z + startpoint[2]) points.append(p) pclpoints.append(p2) surPoints.append(points) pts.addPoints(pclpoints) sur = Part.BSplineSurface() sur.interpolate(surPoints) sur.setVPeriodic() surshape = sur.toShape() surshape.translate(tuple(startpoint)) return (surshape, pts)
def pcl(pts=None): '''create a point cloud of points pts''' if pts == None: pts = pointlist() pcl = Points.Points(pts) Points.show(pcl) return App.ActiveDocument.ActiveObject
def make_points_from_geometry(geometries, distance): for geom in geometries: global_plm = geom.getGlobalPlacement() local_plm = geom.Placement plm = global_plm * local_plm.inverse() prop = geom.getPropertyOfGeometry() if prop is None: continue points_and_normals = prop.getPoints(distance) if len(points_and_normals[0]) == 0: continue points = geom.Document.addObject("Points::Feature", "Points") kernel = Points.Points() kernel.addPoints(points_and_normals[0]) points.Points = kernel points.Placement = plm if len(points_and_normals[1]) > 0 and len( points_and_normals[0]) == len(points_and_normals[1]): points.addProperty("Points::PropertyNormalList", "Normal") points.Normal = points_and_normals[1] points.purgeTouched()
def makeRayBundle(self, raybundle, offset): raysorigin = raybundle.o nrays = np.shape(raysorigin)[1] pp = Points.Points() sectionpoints = [] res = [] for i in range(nrays): if abs(raybundle.t[i]) > 1e-6: x1 = raysorigin[0, i] + offset[0] y1 = raysorigin[1, i] + offset[1] z1 = raysorigin[2, i] + offset[2] x2 = x1 + raybundle.t[i] * raybundle.rayDir[0, i] y2 = y1 + raybundle.t[i] * raybundle.rayDir[1, i] z2 = z1 + raybundle.t[i] * raybundle.rayDir[2, i] res.append(Part.makeLine((x1, y1, z1), (x2, y2, z2))) # draw ray sectionpoints.append((x2, y2, z2)) pp.addPoints(sectionpoints) #Points.show(pp) # draw intersection points per raybundle per field point return (pp, res)
def run(mx, my, dx, dy): ys = my - dy yn = my + dy xw = mx - dx xe = mx + dx dats = [] print(xw, ys, xe, yn) for ix in range(int(math.floor(xw)), int(math.floor(xe)) + 1): for iy in range(int(math.floor(ys)), int(math.floor(yn)) + 1): dat = "Lat" + str(iy) + "Lon" + str(ix) + "Lat" + str( iy + 1) + "Lon" + str(ix + 1) print(dat) dats.append(dat) directory = FreeCAD.ConfigGet("UserAppData") + "/geodat_SRTM/" if not os.path.isdir(directory): print("create " + directory) os.makedirs(directory) for dat in dats: getdata(directory, dat) fn = directory + "/" + dat + ".osm" pts = runfile(fn, xw, xe, ys, yn, mx, my) p = Points.Points(pts) Points.show(p) Gui.updateGui() Gui.SendMsgToActiveView("ViewFit") Gui.SendMsgToActiveView("ViewFit")
def test_flush(self): flush_points = Points.Points([ Card.Card(0, 2), Card.Card(0, 3), Card.Card(0, 4), Card.Card(0, 5) ], Card.Card(1, 9)) flush_points.flush() self.assertTrue(flush_points.points == 4) flush_points = Points.Points([ Card.Card(2, 2), Card.Card(2, 3), Card.Card(2, 4), Card.Card(2, 5) ], Card.Card(2, 9)) flush_points.flush() self.assertTrue(flush_points.points == 5)
def create_pcl(pu, color=(1.0, 0.0, 0.0)): '''create_pcl(pu,color=(1.0,0.0,0.0))''' say(len(pu)) p = Points.Points(pu) Points.show(p) App.ActiveDocument.ActiveObject.ViewObject.ShapeColor = color App.ActiveDocument.points.addObject(App.ActiveDocument.ActiveObject) Gui.updateGui()
def testD(): # kku2=np.array(FreeCAD.kku).reshape(31,31,3) # kku=kku2[10:25,10:20].reshape(150,3) ptsu=[FreeCAD.Vector(tuple(i)) for i in kku] Draft.makeWire(ptsu) Points.show(Points.Points(ptsu)) mode='thin_plate' xy2u = scipy.interpolate.Rbf(kku[:,0],kku[:,1],kku[:,2], function=mode)
def modtest(): '''update the points and the mesh example''' mm=App.ActiveDocument.getObject(pc.Name+'_M') pc=App.ActiveDocument.getObject(pc.Name) ptsk=mm.Mesh.Topology[0] faces=mm.Mesh.Topology[1] ptsk[128].z +=30 pc.Points=Points.Points(ptsk) mm.Mesh=Mesh.Mesh((ptsk,faces))
def init(d): anzp=400 anze=80 la=[random.random() for l in range(anzp)] a=10 if 1: pts=[FreeCAD.Vector(100*x+a*(random.random()-0.5),50*x+a*(random.random()-0.5),0) for x in la] pts += [FreeCAD.Vector(100*random.random(),150*random.random()-50,0) for x in range(anze)] if 1: pts=[FreeCAD.Vector(100*x+a*(random.random()-0.5),200+a*(random.random()-0.5)+50*np.sin(5.0*np.pi*x),0) for x in la] pts += [FreeCAD.Vector(100*random.random(),100*random.random()+150,0) for x in range(anze)] if 1: a=1 pts=[FreeCAD.Vector(100*x+a*(random.random()-0.5),200+a*(random.random()-0.5)+50*np.sin(5.0*np.pi*x),0) for x in la] for ii in range(anze): x=random.random() pts += [FreeCAD.Vector(100*x,80*random.random()+160+50*np.sin(5.0*np.pi*x),0)] # polare Transformation ptsp=[FreeCAD.Vector(p.y*np.cos(p.x*np.pi*0.02),p.y*np.sin(p.x*np.pi*0.02),0) for p in pts] Points.show(Points.Points(ptsp)) App.ActiveDocument.ActiveObject.ViewObject.ShapeColor=(.0,0.,1.) App.ActiveDocument.ActiveObject.ViewObject.PointSize=4 Points.show(Points.Points(pts)) App.ActiveDocument.ActiveObject.ViewObject.ShapeColor=(1.0,0.,0.) App.ActiveDocument.ActiveObject.ViewObject.PointSize=4 # d=5 pts=sorted(pts,key=lambda x: x[0]) return pts
def calculate_points_in_hand(self): if self.has_crib(self.get_turn()): current_player = self.get_turn() other_player = self.get_not_turn() else: other_player = self.get_turn() current_player = self.get_not_turn() crib = self.crib print "Calculating points for %s..." % other_player.name points = Points.Points(other_player.hand.cards, self.top_card) points.run_points() other_player.add_points(points.points) print "Calculating points for %s..." % current_player.name points = Points.Points(current_player.hand.cards, self.top_card) points.run_points() current_player.add_points(points.points) print "Calculating points for crib of %s..." % current_player.name points = Points.Points(crib.cards, self.top_card) points.run_points() current_player.add_points(points.points)
def coordLists2points(x, y, z): ''' convert coordinate lists to Points ''' p = Points.Points() pts = [] try: # simple list n = len(x) except: # numpy n = x.shape(0) for i in range(n): pts.append(FreeCAD.Vector(y[i], x[i], z[i])) p.addPoints(pts) return p
def create_pcl(pu, color=(1.0, 0.0, 0.0)): '''create_pcl(pu,color=(1.0,0.0,0.0))''' say(len(pu)) p = Points.Points(pu) Points.show(p) App.ActiveDocument.ActiveObject.ViewObject.ShapeColor = color App.ActiveDocument.ActiveObject.ViewObject.PointSize = 3 try: App.ActiveDocument.points except: points = App.ActiveDocument.addObject("App::DocumentObjectGroup", "points") App.ActiveDocument.points.addObject(App.ActiveDocument.ActiveObject) Gui.updateGui()
def makePoints(): FreeCAD.newDocument() import Mesh m = Mesh.createSphere(5.0).Points import Points p = Points.Points() l = [] for s in m: l.append(s.Vector) p.addPoints(l) a = FreeCAD.ActiveDocument.addObject("Points::FeaturePython", "Points") a.Points = p PointFeature(a) ViewProviderPoints(a.ViewObject)
def createStepFC(self,i): ts=time.time() objs=pclgroup() (la,lb)=self.ptsl[i].shape # pts=[tuple(self.ptslix[self.ptsl[i][a][b]]) for a in range(la) for b in range(lb)] pts=[] for a in range(la): for b in range(lb): t=tuple(self.ptslix[self.ptsl[i][a][b]]) if np.isnan(t[0]) or np.isnan(t[1]) or np.isnan(t[2]): ##debug print "found error ", t # print (a,b) pass # ignore zero points elif abs(t[0])<10 and abs(t[1])<20: ##debug print "ignore inner point ",t pass else: pts.append(t) pcl=Points.Points(pts) Points.show(pcl) App.activeDocument().recompute() if i%25==0: Gui.SendMsgToActiveView("ViewFit") obj=App.ActiveDocument.ActiveObject obj.ViewObject.ShapeColor=(random.random(),random.random(),random.random()) if len(objs.OutList)==0: obj.Placement=self.obj2.startPosition else: #movePosition=FreeCAD.Placement() #movePosition.Rotation=FreeCAD.Rotation(FreeCAD.Vector(0,0,1),10) movePosition=self.obj2.deltaPosition obj.Placement=objs.OutList[-1].Placement.multiply(movePosition) objs.addObject(obj) te=time.time() say(("createStepFC ",i,"timee",round(te-ts,3))) return obj
def createPointGrid(pts,objname="MyGrid",uc=0,vc=0): '''create the grid point cloud''' assert(len(pts)==(uc+1)*(vc+1)) pc=App.ActiveDocument.getObject(objname) if pc == None: pc = FreeCAD.ActiveDocument.addObject("Points::FeaturePython",objname) Grid(pc) ViewProvider(pc.ViewObject) pc.ViewObject.ShapeColor=(random.random(),random.random(),random.random()) pc.Points=Points.Points(pts) pc.uc=uc pc.vc=vc return pc
def createPointset(grid, extend): (xmin, xmax, ymin, ymax) = extend kx = (xmax - xmin) * 10 ky = (ymax - ymin) * 10 pts = [] for ix in range(grid.shape[0]): for iy in range(grid.shape[1]): if not np.isnan(grid[ix, iy]) and grid[ix, iy] <> 0: pts.append( FreeCAD.Vector(xmin + (0.0 + (xmax - xmin) * ix) / kx, ymin + (0.0 + (ymax - ymin) * iy) / ky, grid[ix, iy])) pout = Points.Points(pts) return pout
def displayQualityPoints(): '''display the quality points as point clouds''' g = FreeCAD.g for q in range(1, 7): pts = [] for v in g.nodes(): #print g.node[v]['quality'] if g.node[v]['quality'] == q: pts.append(g.node[v]['vector']) # print pts if pts <> []: Points.show(Points.Points(pts)) App.ActiveDocument.ActiveObject.ViewObject.ShapeColor = ( random.random(), random.random(), random.random()) App.ActiveDocument.ActiveObject.ViewObject.PointSize = 10 App.ActiveDocument.ActiveObject.Label = "Points Quality " + str(q)
def run(): #default parameters p = { "count": [1000, 'Integer'], "radius": [400, 'Float'], "wave": [100, 'Float'], "debug": [False, 'Boolean'], } # parameter ----------------- t = FreeCAD.ParamGet('User parameter:Plugins/nurbs/' + 'genrandomdat') l = t.GetContents() if l == None: l = [] for k in l: p[k[1]] = k[2] for k in p: if p[k].__class__.__name__ == 'list': typ = p[k][1] if typ == 'Integer': t.SetInt(k, p[k][0]) if typ == 'Boolean': t.SetBool(k, p[k][0]) if typ == 'String': t.SetString(k, p[k][0]) if typ == 'Float': t.SetFloat(k, p[k][0]) p[k] = p[k][0] #-------------------- count = p["count"] ri = p["wave"] rm = p["radius"] kaps = np.random.random(count) * 2 * np.pi mmaa = np.random.random(count) * ri * np.cos(kaps * 5) * np.cos( kaps * 1.3) + rm y = np.cos(kaps) * mmaa x = np.sin(kaps) * mmaa z = np.zeros(count) pps = np.array([x, y, z]).swapaxes(0, 1) goods = [FreeCAD.Vector(tuple(p)) for p in pps] Points.show(Points.Points(goods)) App.ActiveDocument.ActiveObject.ViewObject.ShapeColor = (1.0, 0.0, 0.0) App.ActiveDocument.ActiveObject.ViewObject.PointSize = 10
def preview(self): yid = "ID_" + str(self.uid) yid = yid.replace('-', '_') name = yid label = "PV_" + self.getWrapper().getHeaderText() a = FreeCAD.ActiveDocument.getObject(name) if not self._preview and a != None: FreeCAD.ActiveDocument.removeObject(name) else: try: shape = self.getPinObject("Shape_out") pts = None except: shape = None if shape is None: try: pts = self.getData("Points_out") except: pts = None if pts is not None: import Points if a == None: a = FreeCAD.ActiveDocument.addObject( 'Points::Feature', name) pm = a.Placement a.Points = Points.Points(pts) a.Placement = pm a.Label = label elif shape is not None: if a == None: a = FreeCAD.ActiveDocument.addObject("Part::Feature", name) pm = a.Placement a.Shape = shape a.Placement = pm a.Label = label
def import_image(filename=None, n=10, c=2, inverse=False, kx=10, ky=10, kz=60, gengrid=True, genblock=False, genpoles=False, pointsonly=False): '''import_image(filename=None,n=10,c=2,inverse=False,kx=10,ky=10,kz=60,gengrid=True,genblock=False,genpoles=False,pointsonly=False) ''' display_mathplot = False dataAsPoles = False if filename == None: filename = '/home/microelly2/Schreibtisch/test_nurbs3.png' img = mpimg.imread(filename) ojn = os.path.basename(filename) # grey scaled image and color channel select if len(img.shape) == 2: lum_img = img else: lum_img = img[:, :, c] lum_img = 0.33 * img[:, :, 0] + 0.33 * img[:, :, 1] + 0.34 * img[:, :, 2] (lu, lv) = lum_img.shape if display_mathplot: plt.imshow(lum_img) plt.show() #create a n points border uu2 = np.zeros((lu + 2 * n) * (lv + 2 * n)) uu2 = uu2.reshape(lu + 2 * n, lv + 2 * n) uu2[n:lu + n, n:lv + n] = lum_img lum_img = uu2 (lu, lv) = lum_img.shape bz = kz + 100 if inverse: kz = -kz pts = [] uu = [] for u in range(lu): ul = [] for v in range(lv): # p=FreeCAD.Vector(ky*v,-kx*u,bz-kz*lum_img[u,v]) r = 0.001 p = FreeCAD.Vector(ky * v + r * random.random(), -kx * u + r * random.random(), bz - kz * lum_img[u, v] + r * random.random()) ul.append(p) pts.append(p) uu.append(ul) # show the points p = Points.Points(pts) Points.show(p) App.ActiveDocument.ActiveObject.ViewObject.ShapeColor = (1.0, .0, 1.0) App.ActiveDocument.ActiveObject.Label = "Points " + str(lv) + " " + str( lu) + " _" say((("u, v, points"), u, v, len(pts))) Gui.updateGui() if pointsonly: return tt = Part.BSplineSurface() if dataAsPoles: pols = uu else: tt.interpolate(uu) # flatten the border pols = tt.getPoles() pols2 = np.array(pols) lup, lvp, la = pols2.shape zz = bz bord = n - 2 for u in range(lup): for v in range(bord): op = pols[u][v] nup = FreeCAD.Vector(op.x, op.y, zz) pols[u][v] = nup op = pols[u][-1 - v] nup = FreeCAD.Vector(op.x, op.y, zz) pols[u][-1 - v] = nup for u in range(bord): for v in range(lvp): op = pols[u][v] nup = FreeCAD.Vector(op.x, op.y, zz) pols[u][v] = nup op = pols[-1 - u][v] nup = FreeCAD.Vector(op.x, op.y, zz) pols[-1 - u][v] = nup bs = Part.BSplineSurface() knot_v2 = tt.getVKnots() knot_u2 = tt.getUKnots() mult_u = tt.getUMultiplicities() mult_v = tt.getVMultiplicities() ws = tt.getWeights() bs.buildFromPolesMultsKnots(pols, mult_u, mult_v, knot_u2, knot_v2, False, False, 3, 3, ws) if 1: sha = bs.toShape() # show the poles if genpoles: pols = bs.getPoles() ps = [] for l in pols: for po in l: ps.append(po) p = Points.Points(ps) Points.show(p) App.ActiveDocument.ActiveObject.ViewObject.ShapeColor = (1.0, 1.0, .0) App.ActiveDocument.ActiveObject.Label = 'Poles ' + str(lv) + " " + str( lu) + " _" Gui.updateGui() # the nurbs grid if gengrid: jj = [] rr = lv for i in range(rr + 1): v = bs.vIso((0.0 + i) / rr).toShape() jj.append(v.Edge1) rr = lu for i in range(rr + 1): v = bs.uIso((0.0 + i) / rr).toShape() jj.append(v.Edge1) com = Part.makeCompound(jj) ttt = App.ActiveDocument.addObject('Part::Feature', 'Nurbsgrid ' + str(n) + ' ' + ojn) ttt.ViewObject.DisplayMode = "Wireframe" # ttt.ViewObject.hide() ttt.Shape = com ttt.Placement.Base.z = 10 Gui.updateGui() return #create the solid a = FreeCAD.Vector(0, 0, -bz) b = FreeCAD.Vector(0, -kx * (lu - 1), -bz) c = FreeCAD.Vector(ky * (lv - 1), -kx * (lu - 1), -bz) d = FreeCAD.Vector(ky * (lv - 1), 0, -bz) ad = FreeCAD.Vector(0, 0, bz) bd = FreeCAD.Vector(0, -kx * (lu - 1), bz) cd = FreeCAD.Vector(ky * (lv - 1), -kx * (lu - 1), bz) dd = FreeCAD.Vector(ky * (lv - 1), 0, bz) # for nonlinear borders - experimental if 0: u0e = bs.uIso(0).toShape() p = Part.makePolygon([ad, a, d, dd], True) ll = p.Edges + [u0e.Edge1] f4 = Part.makeFilledFace(Part.__sortEdges__(ll)) Part.show(f4) v0e = bs.vIso(0).toShape() p = Part.makePolygon([bd, b, a, ad], True) ll = p.Edges + [v0e.Edge1] f1 = Part.makeFilledFace(Part.__sortEdges__(ll)) #Part.show(v0e) #Part.show(p) Part.show(f1) u1e = bs.uIso(1).toShape() p = Part.makePolygon([bd, b, c, cd], True) ll = p.Edges + [u1e.Edge1] f2 = Part.makeFilledFace(Part.__sortEdges__(ll)) # f2=Part.Face(Part.__sortEdges__(ll)) #Part.show(u1e) #Part.show(p) Part.show(f2) v1e = bs.vIso(1).toShape() p = Part.makePolygon([dd, d, c, cd], True) ll = p.Edges + [v1e.Edge1] f3 = Part.makeFilledFace(Part.__sortEdges__(ll)) #Part.show(v1e) #Part.show(p) Part.show(f3) p = Part.makePolygon([a, b, c, d], True) f0 = Part.makeFilledFace(p.Edges) Part.show(f0) if 1: nb = App.ActiveDocument.addObject('Part::Spline', 'Nurbs ' + str(n) + ' ' + ojn) nb.Shape = sha.Face1 if genblock: fln = sha.Face1 f0 = Part.Face(Part.makePolygon([a, b, c, d], True)) f1 = Part.Face(Part.makePolygon([ad, bd, b, a], True)) f2 = Part.Face(Part.makePolygon([b, bd, cd, c], True)) f3 = Part.Face(Part.makePolygon([cd, dd, d, c], True)) f4 = Part.Face(Part.makePolygon([ad, a, d, dd], True)) fls = [f0, f1, f2, f3, f4, fln] sh = Part.Shell(fls) sol = Part.Solid(sh) ttt = App.ActiveDocument.addObject('Part::Feature', 'Nurbsblock ' + str(n) + ' ' + ojn) ttt.Shape = sol # ttt.ViewObject.hide() print(lu, lv) return bs
def import_lidar(fn, obj, createPCL=False, useOrigin=False): inFile = File(fn, mode='r') I = inFile.Classification == 2 # I=0 # FreeCAD.infile=inFile pts = inFile.points[I] if 10: scalez = 0.001 scalez = 1. ptsa = [(p[0][0], p[0][1], p[0][2] * scalez) for p in pts] if 1: import Points p = Points.Points(ptsa) Points.show(p) print(pts[0]) ptsb = np.array(ptsa) ptsbxyz = ptsb.swapaxes(0, 1) obj.placementOrigin.Base.x = ptsbxyz[0].min() / 1000. obj.placementOrigin.Base.y = ptsbxyz[1].min() / 1000. obj.placementOrigin.Base.z = ptsbxyz[2].min() / 1000. print(ptsbxyz[0].min(), ptsbxyz[0].max()) x = ptsbxyz[0] - ptsbxyz[0].min() x = x / 1000.0 y = ptsbxyz[1] - ptsbxyz[1].min() y = y / 1000.0 z = ptsbxyz[2] - ptsbxyz[2].min() z = z / 1000.0 ptscxyz = np.array([x, y, z]) ptsc = ptscxyz.swapaxes(0, 1) ptsc = [FreeCAD.Vector(p) for p in ptsc] if createPCL: p = Points.Points(ptsc) Points.show(p) am = App.ActiveDocument.ActiveObject if useOrigin: am.Placement = obj.placementOrigin else: am.Placement = FreeCAD.Placement() obj.xdim = int(round(x.max())) + 1 obj.ydim = int(round(x.max())) + 1 nar = np.zeros(obj.xdim * obj.ydim).reshape(obj.xdim, obj.ydim) for p in ptsc: xi = int(round(p.x)) yi = int(round(p.y)) nar[xi, yi] += p.z ptsd = [] ptse = [] for ix in range(obj.xdim): for iy in range(obj.ydim): if nar[ix, iy] != 0: ptsd += [FreeCAD.Vector(ix, iy, nar[ix, iy])] else: ptse += [FreeCAD.Vector(ix, iy, 0)] if 0: p = Points.Points(ptsd) Points.show(p) App.ActiveDocument.ActiveObject.ViewObject.hide() App.ActiveDocument.ActiveObject.ViewObject.ShapeColor = (0., 1.0, 0.) if 0: p = Points.Points(ptse) Points.show(p) App.ActiveDocument.ActiveObject.ViewObject.ShapeColor = (1., 0.0, 0) obj.nar = list(nar.reshape(obj.xdim * obj.ydim)) return nar
def createFace(obj): nar = np.array(obj.nar).reshape(obj.xdim, obj.ydim) a = obj.uPos c = obj.vPos b = obj.uSize d = obj.vSize d += 1 b += 1 ptsd = [] ptse = [] for ix in range(a, a + b): for iy in range(c, c + d): if nar[ix, iy] != 0: ptsd += [FreeCAD.Vector(ix, iy, nar[ix, iy])] else: ptse += [FreeCAD.Vector(ix, iy, 0)] if obj.createPoints: p = Points.Points(ptsd) Points.show(p) am = App.ActiveDocument.ActiveObject App.ActiveDocument.ActiveObject.ViewObject.ShapeColor = (0., 1.0, 1.) App.ActiveDocument.ActiveObject.Label = "lidar points" if obj.useOrigin: am.Placement = obj.placementOrigin else: am.Placement = FreeCAD.Placement() dat = np.array(ptsd) import scipy import scipy.interpolate modeB = "cubic" xy2h = scipy.interpolate.Rbf(dat[:, 0], dat[:, 1], dat[:, 2], function=modeB) ptsda = [] for ix in range(a, a + b): for iy in range(c, c + d): ptsda += [FreeCAD.Vector(ix, iy, xy2h(ix, iy))] if obj.createPoints: p = Points.Points(ptsda) Points.show(p) am = App.ActiveDocument.ActiveObject App.ActiveDocument.ActiveObject.ViewObject.ShapeColor = (0., 1.0, 0.) App.ActiveDocument.ActiveObject.Label = "interpolated points" if obj.useOrigin: am.Placement = obj.placementOrigin else: am.Placement = FreeCAD.Placement() ptsdarr = np.array(ptsda).reshape(b, d, 3) ta = time.time() if obj.createNurbs: bs = Part.BSplineSurface() bs.interpolate(ptsdarr) fn = "face_" + str(a) + "_" + str(b) + "_" + str(c) + '_' + str(d) obja = App.ActiveDocument.getObject(fn) if obja == None: obja = FreeCAD.ActiveDocument.addObject("Part::Feature", fn) obja.ViewObject.ShapeColor = (random.random(), random.random(), random.random()) obja.ViewObject.hide() obja.Shape = bs.toShape() obj.Shape = bs.toShape() if obj.useOrigin: obja.Placement = obj.placementOrigin else: obja.Placement = FreeCAD.Placement() Gui.updateGui() tb = time.time() # def toUVMesh(ptsda,b=50): if obj.createMesh: topfaces = [] for x in range(b - 1): for y in range(d - 1): topfaces.append( (d * x + y, (d) * x + y + 1, (d) * (x + 1) + y)) topfaces.append(((d) * x + y + 1, (d) * (x + 1) + y, (d) * (x + 1) + y + 1)) t = Mesh.Mesh((ptsda, topfaces)) #Mesh.show(t) fn = "mesh_" + str(a) + "_" + str(b) + "_" + str(c) + '_' + str(d) if obj.meshName == "": obj.meshName = "LidarMesh" fn = obj.meshName mm = App.ActiveDocument.getObject(fn) if mm == None: mm = FreeCAD.ActiveDocument.addObject("Mesh::FeaturePython", fn) mm.ViewObject.ShapeColor = (random.random(), random.random(), random.random()) mm.Mesh = t ViewProvider(mm.ViewObject) mm.ViewObject.Lighting = "Two side" mm.ViewObject.ShapeColor = obj.ViewObject.ShapeColor if obj.useOrigin: mm.Placement = obj.placementOrigin else: mm.Placement = FreeCAD.Placement() tc = time.time() print("nurbs ", tb - ta) print("mesh ", tc - tb)
def createElevationGrid(mode, rbfmode=True, source=None, gridCount=20, zfactor=20, bound=10**5, matplot=False): modeColor = { 'linear': (1.0, 0.3, 0.0), 'thin_plate': (0.0, 1.0, 0.0), 'cubic': (0.0, 1.0, 1.0), 'inverse': (1.0, 1.0, 0.0), 'multiquadric': (1.0, .0, 1.0), 'gaussian': (1.0, 1.0, 1.0), 'quintic': (0.5, 1.0, 0.0) } print("Source", source, "mode", mode) if source <> None: if hasattr(source, "Shape"): # part object pts = [v.Point for v in source.Shape.Vertexes] p = Points.Points(pts) Points.show(p) pob = App.ActiveDocument.ActiveObject pob.ViewObject.PointSize = 10.00 pob.ViewObject.ShapeColor = (1.0, 0.0, 0.0) elif hasattr(source, "Points"): # point cloud pts = source.Points.Points elif source.__class__.__name__ == 'DocumentObjectGroup': hls = App.ActiveDocument.hoehenlinien apts = [] for l in hls.OutList: pts = [v.Point for v in l.Shape.Vertexes] apts += pts pts = apts else: raise Exception("don't know to get points") x = [v[1] for v in pts] y = [v[0] for v in pts] z = [0.01 * v[2] for v in pts] # staerker z = [zfactor * v[2] for v in pts] px = coordLists2points(x, y, z) Points.show(Points.Points(px)) else: # testdata x, y, z = text2coordList(datatext) p = coordLists2points(x, y, z) x = np.array(x) y = np.array(y) z = np.array(z) gridsize = gridCount rbf, xi, yi, zi1 = interpolate(x, y, z, gridsize, mode, rbfmode) # hilfsebene xe = [100, -100, 100, -100] ye = [100, 100, -100, -100] ze = [20, 10, 20, 5] rbf2, xi2, yi2, zi2 = interpolate(xe, ye, ze, gridsize, mode, rbfmode, zi1.shape) #print zi1.shape #print zi2.shape #zi=zi1-zi2 zi = zi1 try: color = modeColor[mode] except: color = (1.0, 0.0, 0.0) xmin = np.min(x) ymin = np.min(y) showFace(rbf, rbf2, x, y, gridsize, color, bound) App.ActiveDocument.ActiveObject.Label = mode + " ZFaktor " + str( zfactor) + " #" rc = App.ActiveDocument.ActiveObject if matplot: showHeightMap(x, y, z, zi) return rc # interpolation for image gridsize = 400 rbf, xi, yi, zi = interpolate(x, y, z, gridsize, mode, rbfmode) rbf2, xi2, yi2, zi2 = interpolate(xe, ye, ze, gridsize, mode, rbfmode, zi.shape) return [rbf, rbf2, x, y, z, zi, zi2]