diff options
author | Jonathan deWerd <jjoonathan@gmail.com> | 2014-06-22 13:35:34 +0400 |
---|---|---|
committer | Jonathan deWerd <jjoonathan@gmail.com> | 2014-06-22 13:35:34 +0400 |
commit | 4d5081cc7cb0c54f0e8d44fa00c0218afa1dfa75 (patch) | |
tree | 525399e46e6b14e6e005e9d50bf817df65cef0d1 | |
parent | 47212348cb45f2f938620ec61a6b97e132683d28 (diff) |
Added beginning of OO mesh-cut interface.
-rw-r--r-- | PolyTest.xcodeproj/project.pbxproj | 7 | ||||
-rw-r--r-- | PolyTest/GridMesh.cpp | 59 | ||||
-rw-r--r-- | PolyTest/GridMesh.h | 42 | ||||
-rw-r--r-- | PolyTest/poly.h | 15 |
4 files changed, 115 insertions, 8 deletions
diff --git a/PolyTest.xcodeproj/project.pbxproj b/PolyTest.xcodeproj/project.pbxproj index 0529dbe0df4..d1956eacdcb 100644 --- a/PolyTest.xcodeproj/project.pbxproj +++ b/PolyTest.xcodeproj/project.pbxproj @@ -10,6 +10,7 @@ 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 */; }; + FC458BC71953F95A00E260AC /* GridMesh.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FC458BC51953F95A00E260AC /* GridMesh.cpp */; }; 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 */; }; @@ -42,6 +43,8 @@ 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; }; + FC458BC51953F95A00E260AC /* GridMesh.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GridMesh.cpp; sourceTree = "<group>"; }; + FC458BC61953F95A00E260AC /* GridMesh.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GridMesh.h; sourceTree = "<group>"; }; 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 */ @@ -93,6 +96,8 @@ FC35456F194BDF3700F3D236 /* poly.h */, FC35456D194BDF2300F3D236 /* poly_demo.cpp */, FC67C07919514DE10077AB72 /* rast_demo.cpp */, + FC458BC51953F95A00E260AC /* GridMesh.cpp */, + FC458BC61953F95A00E260AC /* GridMesh.h */, ); path = PolyTest; sourceTree = "<group>"; @@ -174,6 +179,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + FC458BC71953F95A00E260AC /* GridMesh.cpp in Sources */, FC67C07A19514DE10077AB72 /* rast_demo.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -319,6 +325,7 @@ FC67C07E19514DE10077AB72 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; diff --git a/PolyTest/GridMesh.cpp b/PolyTest/GridMesh.cpp new file mode 100644 index 00000000000..bd0010af86c --- /dev/null +++ b/PolyTest/GridMesh.cpp @@ -0,0 +1,59 @@ +// +// GridMesh.cpp +// PolyTest +// +// Created by Jonathan deWerd on 6/20/14. +// Copyright (c) 2014 a.b.c. All rights reserved. +// + +#include "GridMesh.h" + +GreinerV2f *GreinerV2f::firstVert() { + if (!prev || isBackbone) return this; + GreinerV2f *v = this; + while (v->prev) { + v = v->prev; + if (v->isBackbone) return v; + } + return v; +} + +GreinerV2f *GreinerV2f::lastVert() { + if (!next) return this; + if (next->isBackbone) return this; + GreinerV2f *v = this; + while (v->next) { + v = v->next; + if (v->isBackbone) return v; + } + return v; +} + +GreinerV2f *GreinerV2f::nextPolygon() { + return firstVert()->nextPoly; +} + +GreinerV2f *GreinerV2f::vertAt(float x, float y) { + for(GreinerV2f *v = firstVert(); v; v=v->next) { + if (fabs(x-v->x)+fabs(y-v->y)<tolerance) return v; + } + return nullptr; +} + +bool GreinerV2f::isCyclic() { + if (!prev || !next) return false; + return bool(firstVert()->prev); +} + +void GreinerV2f::setCyclic(bool cyc) { + if (cyc==isCyclic()) return; + GreinerV2f *first = firstVert(); + GreinerV2f *last = lastVert(); + if (cyc) { + first->prev = last; + last->next = first; + } else { + first->prev = nullptr; + last->next = nullptr; + } +}
\ No newline at end of file diff --git a/PolyTest/GridMesh.h b/PolyTest/GridMesh.h new file mode 100644 index 00000000000..8166801438d --- /dev/null +++ b/PolyTest/GridMesh.h @@ -0,0 +1,42 @@ +// +// GridMesh.h +// PolyTest +// +// Created by Jonathan deWerd on 6/20/14. +// Copyright (c) 2014 a.b.c. All rights reserved. +// + +#ifndef __PolyTest__GridMesh__ +#define __PolyTest__GridMesh__ + +#include <iostream> + +struct GreinerV2f { + static tolerance = 1e-5; + float x,y; + GreinerV2f *prev, *next; // Prev,next verts in the *same* polygon + GreinerV2f *nextPoly; // First vertex of the *next* polygon + float alpha; // If this vertex came from an affine comb, this is the mixing factor + bool isIntersection; // True if this vertex was added at an intersection + bool isInterior; + bool isBackbone; // True if nextPoly!=nullptr || exists prevPoly s.t. prevPoly->nextPoly == this + GreinerV2f *entryNeighbor; // Corresp. vertex at same {x,y} in different polygon + GreinerV2f *exitNeighbor; // Exit = ->next->next->next along this polygon *exits* other polygon + GreinerV2f() : next(nullptr), prev(nullptr), + nextPoly(nullptr), entryNeighbor(nullptr), exitNeighbor(nullptr), + isIntersection(false), isBackbone(false) {}; + GreinerV2f *firstVert(); // First vert of this polygon + GreinerV2f *lastVert(); // Last vert of this polygon + GreinerV2f *nextPolygon(); // equiv to firstVert()->nextPoly + GreinerV2f *vertAt(float x, float y); // finds the vert in this poly near x,y + bool isCyclic(); + void setCyclic(bool cyc); +}; + +struct GridMesh { + std::vector<GreinerV2f> v; // Vertex storage. "int up" refers to v[up]. + + +}; + +#endif diff --git a/PolyTest/poly.h b/PolyTest/poly.h index 6e8f307c0d0..cfdf8a37a7e 100644 --- a/PolyTest/poly.h +++ b/PolyTest/poly.h @@ -4,16 +4,15 @@ struct GreinerV2f { float x,y; struct GreinerV2f *next, *prev; // Prev,next verts in the *same* polygon struct GreinerV2f *nextPoly; // First vertex of the *next* polygon + float alpha; // If this vertex came from an affine comb, this is the mixing factor bool isIntersection; // True if this vertex was added at an intersection - 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 + struct GreinerV2f *entryNeighbor; // Corresp. vertex at same {x,y} in different polygon + struct GreinerV2f *exitNeighbor; // Exit = ->next->next->next along this polygon *exits* other polygon GreinerV2f() : next(nullptr), prev(nullptr), - nextPoly(nullptr), neighbour(nullptr), - isIntersection(false), isBackbone(false), - isEntry(false) {}; + nextPoly(nullptr), entryNeighbor(nullptr), exitNeighbor(nullptr), + isIntersection(false), isBackbone(false) {}; }; GreinerV2f* insert_vert_at_intersect(GreinerV2f* poly1left, @@ -67,8 +66,8 @@ GreinerV2f* insert_vert_at_intersect(GreinerV2f* poly1left, newv2->prev = poly2left; // Tell the intersection vertices that they're stacked on top of one another - newv1->neighbour = newv2; - newv2->neighbour = newv1; + newv1->entryNeighbor = newv1->exitNeighbor = newv2; + newv2->entryNeighbor = newv2->exitNeighbor = newv1; return newv1; } |