Пример #1
0
def remesh_beams(liaison, size, rho, immutable_groups, point_metric_file=None):
    # immutable groups
    # wire metric
    metric = None
    if point_metric_file is not None:
        metric_type = check_metric_type(point_metric_file)
        if metric_type == "singular":
            if rho > 1.0:
                # mixed metric
                metric = SingularMetric(size, point_metric_file, rho, True)
            else:
                # analytic metric
                metric = SingularMetric(size, point_metric_file)
        else:
            metric = DistanceMetric(size, point_metric_file)
    polylines = PolylineFactory(liaison.mesh, 135.0, size * 0.2)
    liaison.mesh.resetBeams()
    for entry in polylines.entrySet():
        groupId = entry.key
        for polyline in entry.value:
            if point_metric_file is None:
                metric = ArrayList()
                for v in polyline:
                    metric.add(EuclidianMetric3D(size))
            if liaison.mesh.getGroupName(groupId) in immutable_groups:
                result = polyline
            else:
                result = RemeshPolyline(liaison.mesh, polyline, metric).compute()
            for i in xrange(result.size() - 1):
                liaison.mesh.addBeam(result.get(i), result.get(i + 1), groupId)
    # redefine liaison to remove orphan nodes
    mesh = liaison.getMesh()
    mtb = MeshTraitsBuilder.getDefault3D()
    mtb.addNodeSet()
    liaison = MeshLiaison.create(mesh, mtb)
    return liaison
Пример #2
0
			# New polyline
			polyline = ArrayList()
			listOfPolylines.add(polyline)
			polyline.add(vertices.get(2*b))
		lastVertex = vertices.get(2*b+1)
		polyline.add(lastVertex)
	#print "Group "+str(bId)+" contains "+str(listOfPolylines.size())+" polylines and "+str(listBeamId.size()+1)+" vertices"
	mapGroupToListOfPolylines.put(bId, listOfPolylines)

for bId in bgroupMap.keySet():
	listBeamId = bgroupMap.get(bId)
	listOfPolylines = mapGroupToListOfPolylines.get(bId)
	nrPoly = listOfPolylines.size()
	for numPoly in xrange(nrPoly):
		polyline = listOfPolylines.get(numPoly)
		if options.point_metric_file:
			met = DistanceMetric(options.size, options.point_metric_file)
		elif setAnalytic:
			met = RemeshMetric()
		else:
			met = ArrayList()
			for v in polyline:
				met.add(EuclidianMetric3D(options.size))
		#print "Remesh polyline "+str(numPoly+1)+"/"+str(nrPoly)+" of group "+str(bId)+"/"+str(bgroupMap.size())+" "+str(polyline.size())+" vertices"
		result = RemeshPolyline(newMesh, polyline, met).compute()
		for i in xrange(result.size() - 1):
			newMesh.addBeam(result.get(i), result.get(i+1), bId)
		#print "  New polyline: "+str(result.size())+" vertices"

MeshWriter.writeObject3D(newMesh, outDir, "")
Пример #3
0
SwapEdge(liaison, opts).compute()

writeVTK(liaison)

opts.clear()
opts.put("coplanarity", "0.75")
opts.put("tolerance", "0.6")
opts.put("iterations", str(8))
SmoothNodes3DBg(liaison, opts).compute()

writeVTK(liaison)

#MeshWriter.writeObject3D(liaison.mesh, outDir, ""
polylines = PolylineFactory(liaison.mesh, 135.0, options.size * 0.2)
liaison.mesh.resetBeams()
for entry in polylines.entrySet():
    groupId = entry.key
    for polyline in entry.value:
        listM = ArrayList()
        for v in polyline:
            listM.add(EuclidianMetric3D(options.size))
        #print "Remesh polyline of group "+str(groupId)+"/"+str(polylines.size())+" "+str(polyline.size())+" vertices"
        result = RemeshPolyline(liaison.mesh, polyline, listM).compute()
        for i in xrange(result.size() - 1):
            liaison.mesh.addBeam(result.get(i), result.get(i + 1), groupId)
        #print "  New polyline: "+str(result.size())+" vertices"

if options.recordFile:
    liaison.getMesh().getTrace().finish()
MeshWriter.writeObject3D(liaison.mesh, outDir, "")
Пример #4
0
if (coplanarity >= 0.0):
    smoothOptions.put("coplanarity", str(coplanarity))
SmoothNodes3DBg(liaison, smoothOptions).compute()

## Remove Degenerated
rdOptions = HashMap()
rdOptions.put("rho", str(options.eratio))
RemoveDegeneratedTriangles(liaison, rdOptions).compute()

## Remesh beams
if options.wire > 0.0:
    polylines = PolylineFactory(liaison.mesh, 135.0, options.wire*0.2)
    liaison.mesh.resetBeams()
    for entry in polylines.entrySet():
        groupId = entry.key
        for polyline in entry.value:
            listM = ArrayList()
            for v in polyline:
                listM.add(EuclidianMetric3D(options.wire))
            if liaison.mesh.getGroupName(groupId) in immutable_groups:
                result = polyline
            else:
                result = RemeshPolyline(liaison.mesh, polyline, listM).compute()
            for i in xrange(result.size() - 1):
                liaison.mesh.addBeam(result.get(i), result.get(i+1), groupId)

## Output
MeshWriter.writeObject3D(liaison.getMesh(), outDir, "")
if options.recordFile:
    liaison.getMesh().getTrace().finish()
Пример #5
0
		if lastVertex != vertices.get(2*b):
			# New polyline
			polyline = ArrayList()
			listOfPolylines.add(polyline)
			polyline.add(vertices.get(2*b))
		lastVertex = vertices.get(2*b+1)
		polyline.add(lastVertex)
	print "Group "+str(bId)+" contains "+str(listOfPolylines.size())+" polylines and "+str(listBeamId.size()+1)+" vertices"
	mapGroupToListOfPolylines.put(bId, listOfPolylines)

for bId in bgroupMap.keySet():
	listBeamId = bgroupMap.get(bId)
	listOfPolylines = mapGroupToListOfPolylines.get(bId)
	nrPoly = listOfPolylines.size()
	for numPoly in xrange(nrPoly):
		polyline = listOfPolylines.get(numPoly)
		listM = ArrayList()
		for v in polyline:
			listM.add(EuclidianMetric3D(size))
		#for v in polyline:
		#	print v
		print "Remesh polyline "+str(numPoly+1)+"/"+str(nrPoly)+" of group "+str(bId)+"/"+str(bgroupMap.size())+" "+str(polyline.size())+" vertices"
		result = RemeshPolyline(mesh, polyline, listM).compute()
		for i in xrange(result.size() - 1):
			mesh.addBeam(result.get(i), result.get(i+1), bId)
		print "  New polyline: "+str(result.size())+" vertices"
		#for v in result:
		#	print v

MeshWriter.writeObject3D(mesh, outDir, "")
Пример #6
0
def __remesh(options):
    afront_stderr = getattr(options, 'afront_stderr', None)
    mesh = getattr(options, 'mesh', None)
    liaison = getattr(options, 'liaison', None)
    if not liaison:
        if not mesh:
            mesh = create_mesh(**options)
        liaison = MeshLiaison.create(mesh)

    if options.recordFile:
        liaison.getMesh().getTrace().setDisabled(False)
        liaison.getMesh().getTrace().setLogFile(options.recordFile)
        liaison.getMesh().getTrace().createMesh("mesh", liaison.getMesh())
    if options.immutable_border:
        liaison.mesh.tagFreeEdges(AbstractHalfEdge.IMMUTABLE)

    liaison.getMesh().buildRidges(options.coplanarity)
    if options.immutable_border_group:
        liaison.mesh.tagGroupBoundaries(AbstractHalfEdge.IMMUTABLE)
    else:
        if options.preserveGroups:
            liaison.getMesh().buildGroupBoundaries()

    immutable_groups = []
    if options.immutable_groups_file:
        immutable_groups = read_groups(options.immutable_groups_file)
        liaison.mesh.tagGroups(immutable_groups, AbstractHalfEdge.IMMUTABLE)

    if options.point_metric_file:
        point_metric = DistanceMetric(options.size, options.point_metric_file)
    elif getattr(options, 'point_metric', None):
        point_metric = options.point_metric
    else:
        point_metric = None
    safe_coplanarity = str(max(options.coplanarity, 0.8))

    if options.forced_points:
        if point_metric:
            vi = VertexInsertion(liaison, point_metric)
        else:
            vi = VertexInsertion(liaison, options.size)
        vi.insertNodes(options.forced_points, -1)
        Vertex.setMutable(vi.mutableInserted, False)

    #0
    writeVTK(liaison)
    if options.boundary_angle == None:
        options.boundary_angle = 1.66
    if point_metric:
        point_metric.scaling = 1
        if options.forced_bounds:
            BeamInsertion(liaison.mesh,
                          point_metric).insert(options.forced_bounds[0],
                                               options.forced_bounds[1])
        RemeshSkeleton(liaison, options.boundary_angle, options.size / 100.0,
                       point_metric).compute()
    else:
        RemeshSkeleton(liaison, options.boundary_angle, options.size / 100.0,
                       options.size).compute()
        if options.forced_bounds:
            BeamInsertion(liaison.mesh,
                          options.size).insert(options.forced_bounds[0],
                                               options.forced_bounds[1])

    #1
    writeVTK(liaison)
    opts = HashMap()
    opts.put("coplanarity", safe_coplanarity)
    # Swapping here will help QEMDecimateHalfEdge to decimate more and will
    # reduce the risk to have edge not processed by LengthDecimateHalfEdge
    algo = SwapEdge(liaison, opts)
    algo.maxSwapVolume = (options.size / 4.0)**3
    algo.compute()

    #2
    writeVTK(liaison)

    if options.recordFile:
        cmds = [
            String("assert self.m.checkNoDegeneratedTriangles()"),
            String("assert self.m.checkNoInvertedTriangles()"),
            String("assert self.m.checkVertexLinks()"),
            String("assert self.m.isValid()")
        ]
        liaison.getMesh().getTrace().setHooks(cmds)

    opts.clear()
    opts.put("coplanarity", str(options.coplanarity))
    opts.put("size", str(options.size * 0.3))
    opts.put("maxlength", str(options.size * sqrt(2)))
    algo = QEMDecimateHalfEdge(liaison, opts)
    if point_metric:
        point_metric.scaling = sqrt(2)
        algo.analyticMetric = point_metric
    algo.compute()

    #3
    writeVTK(liaison)
    opts.clear()
    opts.put("size", str(options.size))
    opts.put("freeEdgesOnly", "true")
    opts.put("coplanarity", "-2")
    algo = LengthDecimateHalfEdge(liaison, opts)
    if point_metric:
        algo.analyticMetric = point_metric
    algo.compute()

    #4
    # afront call
    writeVTK(liaison)
    afront_nodes_reader = None
    afront_frozen = None
    if options.afront_path:
        tmp_dir = tempfile.mkdtemp()
        afront_nodes_reader = afront(options.afront_path,
                                     tmp_dir,
                                     liaison.mesh,
                                     options.size,
                                     point_metric,
                                     immutable_groups,
                                     afront_stderr=afront_stderr)
        afront_frozen = afront_insert(liaison, afront_nodes_reader,
                                      options.size, point_metric)
        Vertex.setMutable(afront_frozen, False)

    #5
    writeVTK(liaison)
    if options.afront_path:
        opts.clear()
        opts.put("coplanarity", safe_coplanarity)
        SwapEdge(liaison, opts).compute()

    #6
    writeVTK(liaison)
    opts.clear()
    opts.put("size", str(options.size))
    opts.put("coplanarity", str(options.coplanarity))
    opts.put("minCosAfterSwap", "0.3")
    opts.put("nearLengthRatio", "0.6")
    algo = Remesh(liaison, opts)
    if point_metric:
        point_metric.scaling = 1
        algo.analyticMetric = point_metric
    algo.compute()

    #7
    writeVTK(liaison)

    opts.clear()
    opts.put("coplanarity", safe_coplanarity)
    SwapEdge(liaison, opts).compute()

    #8
    writeVTK(liaison)

    opts.clear()
    opts.put("coplanarity", str(options.coplanarity))
    opts.put("iterations", "2")
    opts.put("size", str(options.size))
    algo = SmoothNodes3DBg(liaison, opts)
    algo.compute()

    #9
    writeVTK(liaison)

    opts.clear()
    opts.put("coplanarity", str(options.coplanarity))
    opts.put("minCosAfterSwap", "0.3")
    SwapEdge(liaison, opts).compute()

    #10
    writeVTK(liaison)
    if not options.afront_path:
        opts.clear()
        opts.put("size", str(options.size))
        algo = Remesh(liaison, opts)
        algo.analyticMetric = point_metric
        algo.compute()

    #11
    writeVTK(liaison)

    opts.clear()
    opts.put("coplanarity", str(options.coplanarity))
    opts.put("size", str(options.size * 0.3))
    opts.put("maxlength", str(options.size * sqrt(2)))
    #workaround for a QEMDecimateHalfEdge bug
    opts.put("freezeNonManifold", "true")
    algo = QEMDecimateHalfEdge(liaison, opts)
    if point_metric:
        point_metric.scaling = sqrt(2)
        algo.analyticMetric = point_metric
    algo.compute()

    #12
    writeVTK(liaison)

    opts.clear()
    opts.put("coplanarity", str(options.coplanarity))
    opts.put("minCosAfterSwap", "0.3")
    SwapEdge(liaison, opts).compute()

    #13
    writeVTK(liaison)

    if afront_frozen:
        Vertex.setMutable(afront_frozen, True)

    opts.clear()
    opts.put("checkNormals", "false")
    ImproveVertexValence(liaison, opts).compute()

    #14
    writeVTK(liaison)

    opts.clear()
    opts.put("coplanarity", safe_coplanarity)
    opts.put("iterations", str(8))
    algo = SmoothNodes3DBg(liaison, opts)
    algo.compute()

    #15
    writeVTK(liaison)

    #MeshWriter.writeObject3D(liaison.mesh, outDir, ""
    polylines = PolylineFactory(liaison.mesh, 135.0, options.size * 0.2)
    liaison.mesh.resetBeams()
    for entry in polylines.entrySet():
        groupId = entry.key
        for polyline in entry.value:
            listM = ArrayList()
            for v in polyline:
                listM.add(EuclidianMetric3D(options.size))
            #print "Remesh polyline of group "+str(groupId)+"/"+str(polylines.size())+" "+str(polyline.size())+" vertices"
            if liaison.mesh.getGroupName(groupId) in immutable_groups:
                result = polyline
            else:
                result = RemeshPolyline(liaison.mesh, polyline,
                                        listM).compute()
            for i in xrange(result.size() - 1):
                liaison.mesh.addBeam(result.get(i), result.get(i + 1), groupId)
            #print "  New polyline: "+str(result.size())+" vertices"

    if options.recordFile:
        liaison.getMesh().getTrace().finish()

    if options.post_script:
        execfile(options.post_script)
    MeshWriter.writeObject3D(liaison.mesh, options.out_dir, "")
Пример #7
0
def __remesh(options):
    afront_stderr = getattr(options, 'afront_stderr', None)
    mesh = getattr(options, 'mesh', None)
    if not mesh:
        mesh = create_mesh(**options)

    liaison = MeshLiaison.create(mesh)
    if options.recordFile:
        liaison.getMesh().getTrace().setDisabled(False)
        liaison.getMesh().getTrace().setLogFile(options.recordFile)
        liaison.getMesh().getTrace().createMesh("mesh", liaison.getMesh())
    if options.immutable_border:
        liaison.mesh.tagFreeEdges(AbstractHalfEdge.IMMUTABLE)

    liaison.getMesh().buildRidges(options.coplanarity)
    if options.immutable_border_group:
        liaison.mesh.tagGroupBoundaries(AbstractHalfEdge.IMMUTABLE)
    else:
        if options.preserveGroups:
            liaison.getMesh().buildGroupBoundaries()

    immutable_groups = []
    if options.immutable_groups_file:
        immutable_groups = read_groups(options.immutable_groups_file)
        liaison.mesh.tagGroups(immutable_groups, AbstractHalfEdge.IMMUTABLE)

    if options.point_metric_file:
        point_metric = DistanceMetric(options.size, options.point_metric_file)
    elif getattr(options, 'point_metric', None):
        point_metric = options.point_metric
    else:
        point_metric = None
    safe_coplanarity = str(max(options.coplanarity, 0.8))

    #0
    writeVTK(liaison)

    if options.recordFile:
        cmds = [ String("assert self.m.checkNoDegeneratedTriangles()"), String("assert self.m.checkNoInvertedTriangles()"), String("assert self.m.checkVertexLinks()"), String("assert self.m.isValid()") ]
        liaison.getMesh().getTrace().setHooks(cmds)

    opts = HashMap()
    opts.put("coplanarity", str(options.coplanarity))
    opts.put("size", str(options.size*0.3))
    opts.put("maxlength", str(options.size*sqrt(2)))
    algo = QEMDecimateHalfEdge(liaison, opts)
    if point_metric:
        point_metric.scaling = sqrt(2)
        algo.analyticMetric = point_metric
    algo.compute()

    #1
    writeVTK(liaison)

    if point_metric:
        point_metric.scaling = 1
        if options.forced_bounds:
            BeamInsertion(liaison.mesh, point_metric).insert(
                options.forced_bounds[0], options.forced_bounds[1])
        RemeshSkeleton(liaison, 1.66, options.size / 100.0, point_metric).compute()
    else:
        RemeshSkeleton(liaison, 1.66, options.size / 100.0, options.size).compute()
        if options.forced_bounds:
            BeamInsertion(liaison.mesh, options.size).insert(
                options.forced_bounds[0], options.forced_bounds[1])

    #2
    writeVTK(liaison)
    opts.clear()
    opts.put("size", str(options.size))
    opts.put("freeEdgesOnly", "true")
    opts.put("coplanarity", "-2")
    algo = LengthDecimateHalfEdge(liaison, opts)
    if point_metric:
        algo.analyticMetric = point_metric
    algo.compute()

    #3
    # afront call
    writeVTK(liaison)
    afront_nodes_reader = None
    afront_frozen = None
    if options.afront_path:
        tmp_dir = tempfile.mkdtemp()
        afront_nodes_reader = afront(options.afront_path, tmp_dir, liaison.mesh,
            options.size, point_metric, immutable_groups, afront_stderr = afront_stderr)
        afront_frozen = afront_insert(liaison, afront_nodes_reader, options.size, point_metric)
        Vertex.setMutable(afront_frozen, False)

	#4
    writeVTK(liaison)
    if options.afront_path:
        opts.clear()
        opts.put("coplanarity", safe_coplanarity)
        SwapEdge(liaison, opts).compute()

    #5
    writeVTK(liaison)
    opts.clear()
    opts.put("size", str(options.size))
    opts.put("coplanarity", str(options.coplanarity))
    opts.put("minCosAfterSwap", "0.3")
    opts.put("nearLengthRatio", "0.6")
    algo = Remesh(liaison, opts)
    if point_metric:
        point_metric.scaling = 1
        algo.analyticMetric = point_metric
    algo.compute()

    #6
    writeVTK(liaison)

    opts.clear()
    opts.put("coplanarity", safe_coplanarity)
    SwapEdge(liaison, opts).compute()

    #7
    writeVTK(liaison)

    opts.clear()
    opts.put("coplanarity", str(options.coplanarity))
    opts.put("iterations", "2")
    opts.put("size", str(options.size))
    algo = SmoothNodes3DBg(liaison, opts)
    algo.compute()

    #8
    writeVTK(liaison)

    opts.clear()
    opts.put("coplanarity", str(options.coplanarity))
    opts.put("minCosAfterSwap", "0.3")
    SwapEdge(liaison, opts).compute()

    #9
    writeVTK(liaison)
    if not options.afront_path:
        opts.clear()
        opts.put("size", str(options.size))
        algo = Remesh(liaison, opts)
        algo.analyticMetric = point_metric
        algo.compute()

    #10
    writeVTK(liaison)

    opts.clear()
    opts.put("coplanarity", str(options.coplanarity))
    opts.put("size", str(options.size*0.3))
    opts.put("maxlength", str(options.size*sqrt(2)))
    #workaround for a QEMDecimateHalfEdge bug
    opts.put("freezeNonManifold", "true")
    algo = QEMDecimateHalfEdge(liaison, opts)
    if point_metric:
        point_metric.scaling = sqrt(2)
        algo.analyticMetric = point_metric
    algo.compute()

    #11
    writeVTK(liaison)

    opts.clear()
    opts.put("coplanarity", str(options.coplanarity))
    opts.put("minCosAfterSwap", "0.3")
    SwapEdge(liaison, opts).compute()

    #12
    writeVTK(liaison)

    if afront_frozen:
        Vertex.setMutable(afront_frozen, True)

    opts.clear()
    opts.put("checkNormals", "false")
    ImproveVertexValence(liaison, opts).compute()

    #13
    writeVTK(liaison)

    opts.clear()
    opts.put("coplanarity", safe_coplanarity)
    opts.put("iterations", str(8))
    algo = SmoothNodes3DBg(liaison, opts)
    algo.compute()

    writeVTK(liaison)

    #MeshWriter.writeObject3D(liaison.mesh, outDir, ""
    polylines=PolylineFactory(liaison.mesh, 135.0, options.size*0.2)
    liaison.mesh.resetBeams()
    for entry in polylines.entrySet():
      groupId = entry.key
      for polyline in entry.value:
            listM = ArrayList()
            for v in polyline:
                listM.add(EuclidianMetric3D(options.size))
            #print "Remesh polyline of group "+str(groupId)+"/"+str(polylines.size())+" "+str(polyline.size())+" vertices"
            if liaison.mesh.getGroupName(groupId) in immutable_groups:
                result = polyline
            else:
                result = RemeshPolyline(liaison.mesh, polyline, listM).compute()
            for i in xrange(result.size() - 1):
                liaison.mesh.addBeam(result.get(i), result.get(i+1), groupId)
            #print "  New polyline: "+str(result.size())+" vertices"

    if options.recordFile:
        liaison.getMesh().getTrace().finish()

    if options.post_script:
        execfile(options.post_script)
    MeshWriter.writeObject3D(liaison.mesh, options.out_dir, "")
Пример #8
0
            # New polyline
            polyline = ArrayList()
            listOfPolylines.add(polyline)
            polyline.add(vertices.get(2 * b))
        lastVertex = vertices.get(2 * b + 1)
        polyline.add(lastVertex)
    #print "Group "+str(bId)+" contains "+str(listOfPolylines.size())+" polylines and "+str(listBeamId.size()+1)+" vertices"
    mapGroupToListOfPolylines.put(bId, listOfPolylines)

for bId in bgroupMap.keySet():
    listBeamId = bgroupMap.get(bId)
    listOfPolylines = mapGroupToListOfPolylines.get(bId)
    nrPoly = listOfPolylines.size()
    for numPoly in xrange(nrPoly):
        polyline = listOfPolylines.get(numPoly)
        if options.point_metric_file:
            met = PointMetric(options.size, options.point_metric_file)
        elif setAnalytic:
            met = RemeshMetric()
        else:
            met = ArrayList()
            for v in polyline:
                met.add(EuclidianMetric3D(options.size))
        #print "Remesh polyline "+str(numPoly+1)+"/"+str(nrPoly)+" of group "+str(bId)+"/"+str(bgroupMap.size())+" "+str(polyline.size())+" vertices"
        result = RemeshPolyline(newMesh, polyline, met).compute()
        for i in xrange(result.size() - 1):
            newMesh.addBeam(result.get(i), result.get(i + 1), bId)
        #print "  New polyline: "+str(result.size())+" vertices"

MeshWriter.writeObject3D(newMesh, outDir, "")