[Bf-blender-cvs] [4721234] soc-2014-nurbs: Added raster algo, viz

Jonathan deWerd noreply at git.blender.org
Fri Jun 27 08:14:33 CEST 2014


Commit: 47212348cb45f2f938620ec61a6b97e132683d28
Author: Jonathan deWerd
Date:   Wed Jun 18 02:11:12 2014 -0400
https://developer.blender.org/rB47212348cb45f2f938620ec61a6b97e132683d28

Added raster algo, viz

===================================================================

M	PolyTest.xcodeproj/project.pbxproj
D	PolyTest/poly.cpp
A	PolyTest/poly.h
M	PolyTest/poly_demo.cpp
A	PolyTest/rast_demo.cpp

===================================================================

diff --git a/PolyTest.xcodeproj/project.pbxproj b/PolyTest.xcodeproj/project.pbxproj
index 406f562..0529dbe 100644
--- a/PolyTest.xcodeproj/project.pbxproj
+++ b/PolyTest.xcodeproj/project.pbxproj
@@ -10,6 +10,9 @@
 		FC35456E194BDF2300F3D236 /* poly_demo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FC35456D194BDF2300F3D236 /* poly_demo.cpp */; };
 		FC354571194BDF7300F3D236 /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FC354570194BDF7300F3D236 /* OpenGL.framework */; };
 		FC354573194BDF7E00F3D236 /* GLUT.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FC354572194BDF7E00F3D236 /* GLUT.framework */; };
+		FC67C07A19514DE10077AB72 /* rast_demo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FC67C07919514DE10077AB72 /* rast_demo.cpp */; };
+		FC67C08019515CBB0077AB72 /* GLUT.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FC354572194BDF7E00F3D236 /* GLUT.framework */; };
+		FC67C08119515CBF0077AB72 /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FC354570194BDF7300F3D236 /* OpenGL.framework */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXCopyFilesBuildPhase section */
@@ -22,14 +25,25 @@
 			);
 			runOnlyForDeploymentPostprocessing = 1;
 		};
+		FC67C07519514DE00077AB72 /* CopyFiles */ = {
+			isa = PBXCopyFilesBuildPhase;
+			buildActionMask = 2147483647;
+			dstPath = /usr/share/man/man1/;
+			dstSubfolderSpec = 0;
+			files = (
+			);
+			runOnlyForDeploymentPostprocessing = 1;
+		};
 /* End PBXCopyFilesBuildPhase section */
 
 /* Begin PBXFileReference section */
 		FC354561194BDED000F3D236 /* PolyTest */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = PolyTest; sourceTree = BUILT_PRODUCTS_DIR; };
 		FC35456D194BDF2300F3D236 /* poly_demo.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = poly_demo.cpp; sourceTree = "<group>"; };
-		FC35456F194BDF3700F3D236 /* poly.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = poly.cpp; sourceTree = "<group>"; };
+		FC35456F194BDF3700F3D236 /* poly.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = poly.h; sourceTree = "<group>"; };
 		FC354570194BDF7300F3D236 /* OpenGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGL.framework; path = System/Library/Frameworks/OpenGL.framework; sourceTree = SDKROOT; };
 		FC354572194BDF7E00F3D236 /* GLUT.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GLUT.framework; path = System/Library/Frameworks/GLUT.framework; sourceTree = SDKROOT; };
+		FC67C07719514DE10077AB72 /* rast_demo */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = rast_demo; sourceTree = BUILT_PRODUCTS_DIR; };
+		FC67C07919514DE10077AB72 /* rast_demo.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = rast_demo.cpp; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
@@ -42,6 +56,15 @@
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
+		FC67C07419514DE00077AB72 /* Frameworks */ = {
+			isa = PBXFrameworksBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+				FC67C08119515CBF0077AB72 /* OpenGL.framework in Frameworks */,
+				FC67C08019515CBB0077AB72 /* GLUT.framework in Frameworks */,
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+		};
 /* End PBXFrameworksBuildPhase section */
 
 /* Begin PBXGroup section */
@@ -59,6 +82,7 @@
 			isa = PBXGroup;
 			children = (
 				FC354561194BDED000F3D236 /* PolyTest */,
+				FC67C07719514DE10077AB72 /* rast_demo */,
 			);
 			name = Products;
 			sourceTree = "<group>";
@@ -66,8 +90,9 @@
 		FC354563194BDED000F3D236 /* PolyTest */ = {
 			isa = PBXGroup;
 			children = (
-				FC35456F194BDF3700F3D236 /* poly.cpp */,
+				FC35456F194BDF3700F3D236 /* poly.h */,
 				FC35456D194BDF2300F3D236 /* poly_demo.cpp */,
+				FC67C07919514DE10077AB72 /* rast_demo.cpp */,
 			);
 			path = PolyTest;
 			sourceTree = "<group>";
@@ -92,6 +117,23 @@
 			productReference = FC354561194BDED000F3D236 /* PolyTest */;
 			productType = "com.apple.product-type.tool";
 		};
+		FC67C07619514DE00077AB72 /* rast_demo */ = {
+			isa = PBXNativeTarget;
+			buildConfigurationList = FC67C07F19514DE10077AB72 /* Build configuration list for PBXNativeTarget "rast_demo" */;
+			buildPhases = (
+				FC67C07319514DE00077AB72 /* Sources */,
+				FC67C07419514DE00077AB72 /* Frameworks */,
+				FC67C07519514DE00077AB72 /* CopyFiles */,
+			);
+			buildRules = (
+			);
+			dependencies = (
+			);
+			name = rast_demo;
+			productName = rast_demo;
+			productReference = FC67C07719514DE10077AB72 /* rast_demo */;
+			productType = "com.apple.product-type.tool";
+		};
 /* End PBXNativeTarget section */
 
 /* Begin PBXProject section */
@@ -114,6 +156,7 @@
 			projectRoot = "";
 			targets = (
 				FC354560194BDED000F3D236 /* PolyTest */,
+				FC67C07619514DE00077AB72 /* rast_demo */,
 			);
 		};
 /* End PBXProject section */
@@ -127,6 +170,14 @@
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
+		FC67C07319514DE00077AB72 /* Sources */ = {
+			isa = PBXSourcesBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+				FC67C07A19514DE10077AB72 /* rast_demo.cpp in Sources */,
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+		};
 /* End PBXSourcesBuildPhase section */
 
 /* Begin XCBuildConfiguration section */
@@ -222,6 +273,24 @@
 			};
 			name = Release;
 		};
+		FC67C07D19514DE10077AB72 /* Debug */ = {
+			isa = XCBuildConfiguration;
+			buildSettings = {
+				GCC_PREPROCESSOR_DEFINITIONS = (
+					"DEBUG=1",
+					"$(inherited)",
+				);
+				PRODUCT_NAME = "$(TARGET_NAME)";
+			};
+			name = Debug;
+		};
+		FC67C07E19514DE10077AB72 /* Release */ = {
+			isa = XCBuildConfiguration;
+			buildSettings = {
+				PRODUCT_NAME = "$(TARGET_NAME)";
+			};
+			name = Release;
+		};
 /* End XCBuildConfiguration section */
 
 /* Begin XCConfigurationList section */
@@ -241,6 +310,15 @@
 				FC35456C194BDED000F3D236 /* Release */,
 			);
 			defaultConfigurationIsVisible = 0;
+			defaultConfigurationName = Release;
+		};
+		FC67C07F19514DE10077AB72 /* Build configuration list for PBXNativeTarget "rast_demo" */ = {
+			isa = XCConfigurationList;
+			buildConfigurations = (
+				FC67C07D19514DE10077AB72 /* Debug */,
+				FC67C07E19514DE10077AB72 /* Release */,
+			);
+			defaultConfigurationIsVisible = 0;
 		};
 /* End XCConfigurationList section */
 	};
diff --git a/PolyTest/poly.cpp b/PolyTest/poly.h
similarity index 55%
rename from PolyTest/poly.cpp
rename to PolyTest/poly.h
index a0251c6..6e8f307 100644
--- a/PolyTest/poly.cpp
+++ b/PolyTest/poly.h
@@ -5,13 +5,15 @@ struct GreinerV2f {
 	struct GreinerV2f *next, *prev; // Prev,next verts in the *same* polygon
 	struct GreinerV2f *nextPoly;   // First vertex of the *next* polygon
 	bool isIntersection; // True if this vertex was added at an intersection
-	bool isEntry; // True if proceeding along this poly with ->next->next will enter the other polygon when this vertex is passed
-	bool isBackbone;
+	bool isEntry; // True if proceeding along this poly with ->next->next->next etc will enter the other polygon when this vertex is passed
+	bool isInterior;
+	bool isBackbone; // True if nextPoly!=nullptr || exists prevPoly s.t. prevPoly->nextPoly == this
 	struct GreinerV2f *neighbour; // Corresp. vertex at same {x,y} in different polygon
 	float alpha; // If this vertex came from an affine comb, this is the mixing factor
 	GreinerV2f() : next(nullptr), prev(nullptr),
 	               nextPoly(nullptr), neighbour(nullptr),
-	               isIntersection(false), isBackbone(false) {};
+	               isIntersection(false), isBackbone(false),
+	               isEntry(false) {};
 };
 
 GreinerV2f* insert_vert_at_intersect(GreinerV2f* poly1left,
@@ -183,3 +185,139 @@ bool point_in_polygon(float x, float y, GreinerV2f* poly) {
 	// Note: return is_even to exclude self-intersecting regions
 	return ccw!=0;
 }
+
+// Polygon clip (subj1\clip + subj2\clip + ...)
+// Fills isEntry for all verts
+// Fills isInterior. isInterior=true on the boundary.
+// Assumes isIntersection has been correctly filled
+void label_entry_exit(GreinerV2f *subj, GreinerV2f *clip) {
+	for (GreinerV2f *poly=subj; poly; poly = poly->nextPoly) {
+		bool interior = point_in_polygon(poly->x, poly->y, clip);
+		poly->isInterior = interior;
+		for (GreinerV2f *vert=poly; vert; vert = vert->next) {
+			if (vert->isIntersection) {
+				vert->isInterior = true;
+				if (interior) vert->isEntry = false;
+				else          vert->isEntry = true;
+				interior = !interior;
+			} else {
+				vert->isInterior = interior;
+			}
+			if (vert->next) {if (vert->next->isBackbone) break;}
+		}
+	}
+}
+
+void next_intersection(GreinerV2f *poly) {
+	
+}
+
+// Fast float->int, courtesy of http://stereopsis.com/sree/fpu2006.html
+// 5x faster on x86. It's not in the hot loop anymore so it probably
+// doesn't really matter. Todo: test and see.
+const double _xs_doublemagic             = 6755399441055744.0;               //2^52 * 1.5,  uses limited precisicion to floor
+const double _xs_doublemagicdelta        = (1.5e-8);                         //almost .5f = .5f + 1e^(number of exp bit)
+const double _xs_doublemagicroundeps     = (.5f-_xs_doublemagicdelta);       //almost .5f = .5f - 1e^(number of exp bit)
+inline static int xs_CRoundToInt(double val) {
+    val = val + _xs_doublemagic;
+    return ((int*)&val)[0]; // 0 for little endian (ok), 1 for big endian (?)
+//    return int32(floor(val+.5)); //Alternative implementation if the trick is buggy
+}
+inline static int xs_FloorToInt(double val) {
+    //return xs_CRoundToInt(val-_xs_doublemagicroundeps);
+	return floor(val); //Alternative implementation if the trick is buggy
+}
+
+//Assumptions: upper right quadrant (default int cast behavior is round-towards-zero)
+std::vector<std::pair<int,int>>
+find_integer_cells_intersecting_line(double x0, double y0, double x1, double y1) {
+	std::vector<std::pair<int,int>> ret;
+	if (x0>x1) { // Ensure order is left to right
+		std::swap(x0,x

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list