示例#1
0
文件: mesh.py 项目: FDiot/code_tympan
 def point_altitude(self, p, face_hint=None):
     p = to_cgal_point(p)
     fh, vh_or_i = self.locate_point(p, face_hint=face_hint)
     if fh is None:  # point p is out of the convex hull of the triangulation
         return UNSPECIFIED_ALTITUDE
     if (isinstance(vh_or_i, Vertex_handle)
             and vh_or_i in self._input_vertices_infos):
         # Point is on a vertex, which is part of an input constraint.
         return self.altitude_for_input_vertex(vh_or_i)
     # point is on an edge and get a finite face if needed
     if isinstance(vh_or_i, int) and self.cdt.is_infinite(fh):
         fh, _ = self.mirror_half_edge(fh, vh_or_i)
         assert not self.cdt.is_infinite(fh)
     triangle = self.triangle3d_for_face(fh)
     p2 = Point_3(p.x(), p.y(), 0)
     vline = Line_3(p2, Z_VECTOR)
     inter = intersection(triangle, vline)
     if not inter.is_Point_3():
         raise InconsistentGeometricModel("Can not compute elevation",
                                          witness_point=(p.x(), p.y()))
     p3 = inter.get_Point_3()
     alti = p3.z()
     dist = abs((p3 - p2).squared_length() - alti**2)
     assert dist <= _PROXIMITY_THRESHOLD * 1e-3 + _PROXIMITY_THRESHOLD * (
         alti**2
     ), ("unexpected distance between point and its projection : %f (threshold = %f, altitude = %f)"
         % (dist, _PROXIMITY_THRESHOLD, alti))
     return alti
def getSurfaceInfoAndCentroidnormal(rootObj, SurfaceInfo, centroidNormals, rootCentroid = None, rootPolygon = None) : 
    for subObj in rootObj.findall('t2_node') : 
        pointsTest = []
        zCor = float(infoMap[subObj.get('lid')])
        xCor = float(subObj.get('x'))
        yCor = float(subObj.get('y'))
        currentPoint = Point_3(xCor, yCor, zCor)
        pointsTest.append(currentPoint)
        if rootObj.tag == 't2_node' : 
            pointsTest.append(Point_3(float(rootObj.get('x')), float(rootObj.get('y')), float(infoMap[rootObj.get('lid')])))
        for childNode in subObj.findall('t2_node') : 
            pointsTest.append(Point_3(float(childNode.get('x')), float(childNode.get('y')), float(infoMap[childNode.get('lid')])))
        if len(pointsTest) == 1 : return
        if len(pointsTest) == 2 : pointsTest.append(pointsTest[0])
        finalDirection = leastsq(lineFitFunc, [pointsTest[-2].x() - pointsTest[0].x(), pointsTest[-2].y() - pointsTest[0].y(), pointsTest[-2].z() - pointsTest[0].z()], (pointsTest[0], pointsTest))
        finalNormal = Vector_3(finalDirection[0][0], finalDirection[0][1], finalDirection[0][2])
        if math.isnan(finalNormal.x()) or math.isnan(finalNormal.y()) or math.isnan(finalNormal.z()) or (finalNormal.x() == 0 and finalNormal.y() == 0 and finalNormal.z() == 0):
            finalNormal = Vector_3(pointsTest[-1].x() - pointsTest[0].x(), pointsTest[-1].y() - pointsTest[0].y(), pointsTest[-1].z() - pointsTest[0].z())
        centroidNormals.append((Point_3(xCor, yCor, zCor), finalNormal))
        
        pointList = []
        for newArea in subObj.findall('t2_area') : 
            for newPath in newArea.findall('t2_path') : 
                pathCorStr = newPath.get('d').split()
                allCors = [float(pathCorStr[i]) for i in range(0, len(pathCorStr)) if i % 3 != 0]
                pointList = [Point_3(allCors[i], allCors[i + 1], zCor) for i in range(0, len(allCors), 2)]
#                pointList = [Point_2(allCors[i], allCors[i + 1]) for i in range(0, len(allCors), 2)]
        subPolygon = None
        if pointList : 
            subPolygon = [Segment_3(pointList[i], pointList[i + 1]) for i in range(0, len(pointList) - 1)]
            if rootPolygon : 
#                rootTree = AABB_tree_Segment_3_soup(rootPolygon)
                for newPt in pointList : 
                    newRay = Ray_3(rootCentroid, Vector_3(currentPoint, newPt))
#                    newIntersections = []
#                    rootTree.all_intersections(newRay, newIntersections)
                    newIntersections = [newObj.get_Point_3() for newObj in [intersection(newRay, newSegment) for newSegment in rootPolygon] if (not newObj.empty()) and newObj.is_Point_3()]
#                    newRay = Ray_2(Point_2(rootCentroid.x(), rootCentroid.y()), Vector_2(Point_2(currentPoint.x(), currentPoint.y()), newPt))
#                    newIntersections = [newObj.get_Point_2() for newObj in [intersection(newRay, newSegment) for newSegment in rootPolygon] if (not newObj.empty()) and newObj.is_Point_2()]
                    if len(newIntersections) == 0 : 
                        print 'opps!'
                    SurfaceInfo.extend([Segment_3(newPt, newPoint) for newPoint in newIntersections])
#                    SurfaceInfo.extend([Segment_3(Point_3(newPt.x(), newPt.y(), zCor), Point_3(newPoint.x(), newPoint.y(), rootCentroid.z())) for newPoint in newIntersections])
#            subPolygon = [Segment_2(pointList[i], pointList[i + 1]) for i in range(0, len(pointList)) if i != len(pointList) - 1]
        if subPolygon is not None : 
            SurfaceInfo.extend(subPolygon)
#            SurfaceInfo.extend([Segment_3(Point_3(newSegment.source().x(), newSegment.source().y(), zCor), Point_3(newSegment.target().x(), newSegment.target().y(), zCor)) for newSegment in subPolygon])
            getSurfaceInfoAndCentroidnormal(subObj, SurfaceInfo, centroidNormals, currentPoint, subPolygon)
        else : 
            getSurfaceInfoAndCentroidnormal(subObj, SurfaceInfo, centroidNormals, rootCentroid, rootPolygon)
def get_fucking_correspondence(tri, ray):
    result = intersection(tri, ray)
    if result.is_Point_3():
        return result.get_Point_3()
    return 0
    fucking_ray.append(ray)
    back_ray.append(ray_back)
count = 0
nomiss_points_ind = []
for i in range(len(fucking_ray)):
    tmp = []
    Points = []
    for j in range(len(faces)):
        a = Point_3(vertics[faces[j][0] - 1][0], vertics[faces[j][0] - 1][1],
                    vertics[faces[j][0] - 1][2])
        b = Point_3(vertics[faces[j][1] - 1][0], vertics[faces[j][1] - 1][1],
                    vertics[faces[j][1] - 1][2])
        c = Point_3(vertics[faces[j][2] - 1][0], vertics[faces[j][2] - 1][1],
                    vertics[faces[j][2] - 1][2])
        tri = Triangle_3(a, b, c)
        result = intersection(fucking_ray[i], tri)
        if result.is_Point_3():
            #print("before: ", str(vertics[faces[j][0]-1]))
            #print("after: ", str(result.get_Point_3()))
            inter = str(result.get_Point_3)
            tmp.append(str(result.get_Point_3()))
            break

    try:
        Points.append(tmp[len(tmp) - 1])
        #print(tmp[len(tmp)-1])
        nomiss_points_ind.append(i)
    except:
        for j in range(len(faces)):
            a = Point_3(vertics[faces[j][0] - 1][0],
                        vertics[faces[j][0] - 1][1],
tail = [
    Point_2(1, 0),
    Point_2(2, 2),
    Point_2(1, 2),
    Point_2(2, 1),
    Point_2(-1, 2),
    Point_2(2, -1)
]

#point_2 untuk 2 dimensi dan segment_2 untuk 2 dimensi juga

intersectionPoint = []

for i in range(len(segments)):
    for j in range(i + 1, len(segments)):
        inter = intersection(
            segments[i], segments[j])  #untuk cek ada intersection atau engga
        if inter.is_Point_2() == True:
            k = Point_2(inter.get_Point_2().x(), inter.get_Point_2().y())
            #karena kalau bertemu sama-sama diujung bukan intersection
            if k in head:
                if head[i] == head[j] or tail[i] == head[j] or head[i] == tail[
                        j]:
                    continue
            elif k in tail:
                if tail[i] == tail[j] or tail[i] == head[j] or head[i] == tail[
                        j]:
                    continue
            else:
                print('Titik potong segment ', i + 1, 'dengan ', j + 1, ': ',
                      '(',
                      inter.get_Point_2().x(), ',',
 if len(SurfaceInfo) == 0 : 
     print newTree.get('oid') + ' no surface!'
     continue
 areaMap = {};
 normalMap = {}
 for newNode in nodeMap : 
     planeNormal = findRightNormal(newNode[1], centroidNormals)
     sqLen = math.sqrt(planeNormal.squared_length())
     cosinXY = abs(planeNormal.z()) / sqLen
     cosinXZ = abs(planeNormal.y()) / sqLen
     cosinYZ = abs(planeNormal.x()) / sqLen
     if cosinXY == 0 and cosinXZ == 0 and cosinYZ == 0 : 
         areaMap[newNode[0]] = 0
         continue
     planeQuery = Plane_3(newNode[1], planeNormal)
     newIntersections = [newObj.get_Point_3() for newObj in [intersection(planeQuery, newSegment) for newSegment in SurfaceInfo] if (not newObj.empty()) and newObj.is_Point_3()]
     if len(newIntersections) == 0 : 
         print 'big opps!'
     allCrossSectionPoints = []
     maxDist = newNode[2] * 1.2
     for newPt in newIntersections : 
         if squared_distance(newPt, newNode[1]) > maxDist : continue
         if cosinXY != 0 : 
             allCrossSectionPoints.append(Point_2(newPt.x(), newPt.y()))
         elif cosinXZ != 0 : 
             allCrossSectionPoints.append(Point_2(newPt.x(), newPt.z()))
         else : 
             allCrossSectionPoints.append(Point_2(newPt.y(), newPt.z()))
     convexPoints = []
     CGAL_Convex_hull_2.convex_hull_2(allCrossSectionPoints, convexPoints)
     AAA = Polygon_2(convexPoints)