Add a Point in Polygon routine
authorAntonio Ospite <ospite@studenti.unina.it>
Wed, 24 Jan 2007 16:11:28 +0000 (17:11 +0100)
committerAntonio Ospite <ospite@studenti.unina.it>
Thu, 24 Sep 2009 16:56:58 +0000 (18:56 +0200)
Signed-off-by: Antonio Ospite <ospite@studenti.unina.it>
vrm.py

diff --git a/vrm.py b/vrm.py
index b121765..da71fab 100755 (executable)
--- a/vrm.py
+++ b/vrm.py
@@ -99,9 +99,8 @@ progress = None
 class config:
     polygons = dict()
     polygons['SHOW'] = True
-    polygons['SHADING'] = 'FLAT'
-    #polygons['HSR'] = 'PAINTER' # 'PAINTER' or 'NEWELL'
-    polygons['HSR'] = 'NEWELL'
+    polygons['SHADING'] = 'FLAT' # FLAT or TOON
+    polygons['HSR'] = 'PAINTER' # PAINTER or NEWELL
     # Hidden to the user for now
     polygons['EXPANSION_TRICK'] = True
 
@@ -110,7 +109,7 @@ class config:
     edges = dict()
     edges['SHOW'] = False
     edges['SHOW_HIDDEN'] = False
-    edges['STYLE'] = 'MESH' # or SILHOUETTE
+    edges['STYLE'] = 'MESH' # MESH or SILHOUETTE
     edges['WIDTH'] = 2
     edges['COLOR'] = [0, 0, 0]
 
@@ -119,9 +118,6 @@ class config:
     output['ANIMATION'] = False
     output['JOIN_OBJECTS'] = True
 
-    #output['FORMAT'] = 'SWF'
-    #output['ANIMATION'] = True
-
 
 # Utility functions
 print_debug = False
@@ -320,6 +316,34 @@ class HSR:
 
     isVertInside = staticmethod(isVertInside)
 
+
+    def det(a, b, c):
+        return ((b[0] - a[0]) * (c[1] - a[1]) -
+                (b[1] - a[1]) * (c[0] - a[0]) )
+    
+    det = staticmethod(det)
+
+    def pointInPolygon(q, P):
+        is_in = False
+
+        point_at_infinity = NMesh.Vert(-INF, q.co[1], -INF)
+
+        det = HSR.det
+
+        for i in range(len(P.v)):
+            p0 = P.v[i-1]
+            p1 = P.v[i]
+            if (det(q.co, point_at_infinity.co, p0.co)<0) != (det(q.co, point_at_infinity.co, p1.co)<0):
+                if det(p0.co, p1.co, q.co) == 0 :
+                    #print "On Boundary"
+                    return False
+                elif (det(p0.co, p1.co, q.co)<0) != (det(p0.co, p1.co, point_at_infinity.co)<0):
+                    is_in = not is_in
+
+        return is_in
+
+    pointInPolygon = staticmethod(pointInPolygon)
+
     def projectionsOverlap(f1, f2):
         """ If you have nonconvex, but still simple polygons, an acceptable method
         is to iterate over all vertices and perform the Point-in-polygon test[1].
@@ -336,7 +360,8 @@ class HSR:
 
             # If a point of f1 in inside f2, there is an overlap!
             v1 = f1.v[i]
-            if HSR.isVertInside(f2, v1):
+            #if HSR.isVertInside(f2, v1):
+            if HSR.pointInPolygon(v1, f2):
                 return True
 
             # If not the polygon can be ovelap as well, so we check for
@@ -1723,7 +1748,7 @@ class Renderer:
             outputWriter.open(startFrame, endFrame)
         
         # Do the rendering process frame by frame
-        print "Start Rendering of %d frames" % (endFrame-startFrame)
+        print "Start Rendering of %d frames" % (endFrame-startFrame+1)
         for f in xrange(startFrame, endFrame+1):
             print "\n\nFrame: %d" % f
             context.currentFrame(f)
@@ -2517,6 +2542,7 @@ class Renderer:
             if edgestyleSelect(e, mesh):
                 e.sel = 1
         """
+        #
 
 
 # ---------------------------------------------------------------------
@@ -2695,6 +2721,9 @@ class GUI:
         elif evt == GUI.evtOutFormatMenu:
             i = GUI.outFormatMenu.val - 1
             config.output['FORMAT']= outputWriters.keys()[i]
+            # Set the new output file
+            global outputfile
+            outputfile = Blender.sys.splitext(basename)[0] + "." + str(config.output['FORMAT']).lower()
 
         elif evt == GUI.evtAnimToggle:
             config.output['ANIMATION'] = bool(GUI.animToggle.val)