working on DECL isosurface tools
This commit is contained in:
parent
39d7fa0430
commit
db1fe9e327
@ -33,34 +33,47 @@ Point Vertex::coords(unsigned long int idx){
|
|||||||
return P;
|
return P;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Halfedge::Halfedge(){
|
||||||
|
}
|
||||||
|
|
||||||
|
Halfedge::~Halfedge(){
|
||||||
|
|
||||||
|
}
|
||||||
unsigned long int Halfedge::v1(unsigned long int edge){
|
unsigned long int Halfedge::v1(unsigned long int edge){
|
||||||
return HalfEdge(0,edge);
|
return data(0,edge);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long int Halfedge::v2(unsigned long int edge){
|
unsigned long int Halfedge::v2(unsigned long int edge){
|
||||||
return HalfEdge(1,edge);
|
return data(1,edge);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long int Halfedge::face(unsigned long int edge){
|
unsigned long int Halfedge::face(unsigned long int edge){
|
||||||
return HalfEdge(2,edge);
|
return data(2,edge);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long int Halfedge::twin(unsigned long int edge){
|
unsigned long int Halfedge::twin(unsigned long int edge){
|
||||||
return HalfEdge(3,edge);
|
return data(3,edge);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long int Halfedge::prev(unsigned long int edge){
|
unsigned long int Halfedge::prev(unsigned long int edge){
|
||||||
return HalfEdge(4,edge);
|
return data(4,edge);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long int Halfedge::next(unsigned long int edge){
|
unsigned long int Halfedge::next(unsigned long int edge){
|
||||||
return HalfEdge(5,edge);
|
return data(5,edge);
|
||||||
|
}
|
||||||
|
|
||||||
|
DECL::DECL(){
|
||||||
|
}
|
||||||
|
|
||||||
|
DECL::~DECL(){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DECL::LocalIsosurface(const DoubleArray A, double value, int i, int j, int k){
|
void DECL::LocalIsosurface(const DoubleArray A, double value, int i, int j, int k){
|
||||||
Point P,Q;
|
Point P,Q;
|
||||||
Point PlaceHolder;
|
Point PlaceHolder;
|
||||||
double temp;
|
|
||||||
Point C0,C1,C2,C3,C4,C5,C6,C7;
|
Point C0,C1,C2,C3,C4,C5,C6,C7;
|
||||||
|
|
||||||
int TriangleCount;
|
int TriangleCount;
|
||||||
@ -78,10 +91,6 @@ void DECL::LocalIsosurface(const DoubleArray A, double value, int i, int j, int
|
|||||||
// Values from array 'A' at the cube corners
|
// Values from array 'A' at the cube corners
|
||||||
double CubeValues[8];
|
double CubeValues[8];
|
||||||
|
|
||||||
int Nx = A.size(0);
|
|
||||||
int Ny = A.size(1);
|
|
||||||
int Nz = A.size(2);
|
|
||||||
|
|
||||||
// Points corresponding to cube corners
|
// Points corresponding to cube corners
|
||||||
C0.x = 0.0; C0.y = 0.0; C0.z = 0.0;
|
C0.x = 0.0; C0.y = 0.0; C0.z = 0.0;
|
||||||
C1.x = 1.0; C1.y = 0.0; C1.z = 0.0;
|
C1.x = 1.0; C1.y = 0.0; C1.z = 0.0;
|
||||||
@ -208,62 +217,61 @@ void DECL::LocalIsosurface(const DoubleArray A, double value, int i, int j, int
|
|||||||
nTris = TriangleCount;
|
nTris = TriangleCount;
|
||||||
|
|
||||||
// Now add the local values to the DECL data structure
|
// Now add the local values to the DECL data structure
|
||||||
IntArray HalfEdge(6,nTris*3);
|
halfedge.data.resize(6,nTris*3);
|
||||||
DoubleArray EdgeAngles(nTris*3);
|
|
||||||
int idx_edge=0;
|
int idx_edge=0;
|
||||||
for (int idx=0; idx<TriangleCount; idx++){
|
for (int idx=0; idx<TriangleCount; idx++){
|
||||||
int V1 = Triangles(0,idx);
|
int V1 = Triangles(0,idx);
|
||||||
int V2 = Triangles(1,idx);
|
int V2 = Triangles(1,idx);
|
||||||
int V3 = Triangles(2,idx);
|
int V3 = Triangles(2,idx);
|
||||||
// first edge: V1->V2
|
// first edge: V1->V2
|
||||||
HalfEdge(0,idx_edge) = V1; // first vertex
|
halfedge.data(0,idx_edge) = V1; // first vertex
|
||||||
HalfEdge(1,idx_edge) = V2; // second vertex
|
halfedge.data(1,idx_edge) = V2; // second vertex
|
||||||
HalfEdge(2,idx_edge) = idx; // triangle
|
halfedge.data(2,idx_edge) = idx; // triangle
|
||||||
HalfEdge(3,idx_edge) = -1; // twin
|
halfedge.data(3,idx_edge) = -1; // twin
|
||||||
HalfEdge(4,idx_edge) = idx_edge+2; // previous edge
|
halfedge.data(4,idx_edge) = idx_edge+2; // previous edge
|
||||||
HalfEdge(5,idx_edge) = idx_edge+1; // next edge
|
halfedge.data(5,idx_edge) = idx_edge+1; // next edge
|
||||||
idx_edge++;
|
idx_edge++;
|
||||||
// second edge: V2->V3
|
// second edge: V2->V3
|
||||||
HalfEdge(0,idx_edge) = V2; // first vertex
|
halfedge.data(0,idx_edge) = V2; // first vertex
|
||||||
HalfEdge(1,idx_edge) = V3; // second vertex
|
halfedge.data(1,idx_edge) = V3; // second vertex
|
||||||
HalfEdge(2,idx_edge) = idx; // triangle
|
halfedge.data(2,idx_edge) = idx; // triangle
|
||||||
HalfEdge(3,idx_edge) = -1; // twin
|
halfedge.data(3,idx_edge) = -1; // twin
|
||||||
HalfEdge(4,idx_edge) = idx_edge-1; // previous edge
|
halfedge.data(4,idx_edge) = idx_edge-1; // previous edge
|
||||||
HalfEdge(5,idx_edge) = idx_edge+1; // next edge
|
halfedge.data(5,idx_edge) = idx_edge+1; // next edge
|
||||||
idx_edge++;
|
idx_edge++;
|
||||||
// third edge: V3->V1
|
// third edge: V3->V1
|
||||||
HalfEdge(0,idx_edge) = V3; // first vertex
|
halfedge.data(0,idx_edge) = V3; // first vertex
|
||||||
HalfEdge(1,idx_edge) = V1; // second vertex
|
halfedge.data(1,idx_edge) = V1; // second vertex
|
||||||
HalfEdge(2,idx_edge) = idx; // triangle
|
halfedge.data(2,idx_edge) = idx; // triangle
|
||||||
HalfEdge(3,idx_edge) = -1; // twin
|
halfedge.data(3,idx_edge) = -1; // twin
|
||||||
HalfEdge(4,idx_edge) = idx_edge-1; // previous edge
|
halfedge.data(4,idx_edge) = idx_edge-1; // previous edge
|
||||||
HalfEdge(5,idx_edge) = idx_edge-2; // next edge
|
halfedge.data(5,idx_edge) = idx_edge-2; // next edge
|
||||||
idx_edge++;
|
idx_edge++;
|
||||||
}
|
}
|
||||||
int EdgeCount=idx_edge;
|
int EdgeCount=idx_edge;
|
||||||
for (int idx=0; idx<EdgeCount; idx++){
|
for (int idx=0; idx<EdgeCount; idx++){
|
||||||
int V1=HalfEdge(0,idx);
|
int V1=halfedge.data(0,idx);
|
||||||
int V2=HalfEdge(1,idx);
|
int V2=halfedge.data(1,idx);
|
||||||
// Find all the twins within the cube
|
// Find all the twins within the cube
|
||||||
for (int jdx=0; idx<EdgeCount; jdx++){
|
for (int jdx=0; idx<EdgeCount; jdx++){
|
||||||
if (HalfEdge(1,jdx) == V1 && HalfEdge(0,jdx) == V2){
|
if (halfedge.data(1,jdx) == V1 && halfedge.data(0,jdx) == V2){
|
||||||
// this is the pair
|
// this is the pair
|
||||||
HalfEdge(3,idx) = jdx;
|
halfedge.data(3,idx) = jdx;
|
||||||
HalfEdge(3,jdx) = idx;
|
halfedge.data(3,jdx) = idx;
|
||||||
}
|
}
|
||||||
if (HalfEdge(1,jdx) == V2 && HalfEdge(0,jdx) == V1 && !(idx==jdx)){
|
if (halfedge.data(1,jdx) == V2 && halfedge.data(0,jdx) == V1 && !(idx==jdx)){
|
||||||
std::printf("WARNING: half edges with identical orientation! \n");
|
std::printf("WARNING: half edges with identical orientation! \n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Use "ghost" twins if edge is on a cube face
|
// Use "ghost" twins if edge is on a cube face
|
||||||
P = cellvertices(V1);
|
P = cellvertices(V1);
|
||||||
Q = cellvertices(V2);
|
Q = cellvertices(V2);
|
||||||
if (P.x == 0.0 && Q.x == 0.0) HalfEdge(3,idx_edge) = -1; // ghost twin for x=0 face
|
if (P.x == 0.0 && Q.x == 0.0) halfedge.data(3,idx_edge) = -1; // ghost twin for x=0 face
|
||||||
if (P.x == 1.0 && Q.x == 1.0) HalfEdge(3,idx_edge) = -2; // ghost twin for x=1 face
|
if (P.x == 1.0 && Q.x == 1.0) halfedge.data(3,idx_edge) = -2; // ghost twin for x=1 face
|
||||||
if (P.y == 0.0 && Q.y == 0.0) HalfEdge(3,idx_edge) = -3; // ghost twin for y=0 face
|
if (P.y == 0.0 && Q.y == 0.0) halfedge.data(3,idx_edge) = -3; // ghost twin for y=0 face
|
||||||
if (P.y == 1.0 && Q.y == 1.0) HalfEdge(3,idx_edge) = -4; // ghost twin for y=1 face
|
if (P.y == 1.0 && Q.y == 1.0) halfedge.data(3,idx_edge) = -4; // ghost twin for y=1 face
|
||||||
if (P.z == 0.0 && Q.z == 0.0) HalfEdge(3,idx_edge) = -5; // ghost twin for z=0 face
|
if (P.z == 0.0 && Q.z == 0.0) halfedge.data(3,idx_edge) = -5; // ghost twin for z=0 face
|
||||||
if (P.z == 1.0 && Q.z == 1.0) HalfEdge(3,idx_edge) = -6; // ghost twin for z=1 face
|
if (P.z == 1.0 && Q.z == 1.0) halfedge.data(3,idx_edge) = -6; // ghost twin for z=1 face
|
||||||
}
|
}
|
||||||
// Map vertices to global coordinates
|
// Map vertices to global coordinates
|
||||||
for (int idx=0;idx<NewVertexCount;idx++) {
|
for (int idx=0;idx<NewVertexCount;idx++) {
|
||||||
@ -273,7 +281,6 @@ void DECL::LocalIsosurface(const DoubleArray A, double value, int i, int j, int
|
|||||||
P.z += k;
|
P.z += k;
|
||||||
cellvertices(idx) = P;
|
cellvertices(idx) = P;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Point DECL::TriNormal(int edge)
|
Point DECL::TriNormal(int edge)
|
||||||
@ -281,9 +288,15 @@ Point DECL::TriNormal(int edge)
|
|||||||
Point P,Q;
|
Point P,Q;
|
||||||
double ux,uy,uz,vx,vy,vz;
|
double ux,uy,uz,vx,vy,vz;
|
||||||
double nx,ny,nz,len;
|
double nx,ny,nz,len;
|
||||||
if (edge == -1) P.x = 1.0; P.y = 0.0; P.z = 0.0; // x cube face
|
if (edge == -1){
|
||||||
else if (edge == -2) P.x = 0.0; P.y = 1.0; P.z = 0.0; // y cube face
|
P.x = 1.0; P.y = 0.0; P.z = 0.0; // x cube face
|
||||||
else if (edge == -3) P.x = 0.0; P.y = 0.0; P.z = 1.0; // z cube face
|
}
|
||||||
|
else if (edge == -2){
|
||||||
|
P.x = 0.0; P.y = 1.0; P.z = 0.0; // y cube face
|
||||||
|
}
|
||||||
|
else if (edge == -3){
|
||||||
|
P.x = 0.0; P.y = 0.0; P.z = 1.0; // z cube face
|
||||||
|
}
|
||||||
else{
|
else{
|
||||||
// coordinates for first edge
|
// coordinates for first edge
|
||||||
P = vertex.coords(halfedge.v1(edge));
|
P = vertex.coords(halfedge.v1(edge));
|
||||||
|
@ -32,8 +32,8 @@ public:
|
|||||||
unsigned long int next(unsigned long int edge);
|
unsigned long int next(unsigned long int edge);
|
||||||
unsigned long int prev(unsigned long int edge);
|
unsigned long int prev(unsigned long int edge);
|
||||||
|
|
||||||
|
Array<unsigned long int> data;
|
||||||
private:
|
private:
|
||||||
Array<unsigned long int> HalfEdge;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// DECL
|
// DECL
|
||||||
@ -45,7 +45,7 @@ public:
|
|||||||
unsigned long int face();
|
unsigned long int face();
|
||||||
Vertex vertex;
|
Vertex vertex;
|
||||||
Halfedge halfedge;
|
Halfedge halfedge;
|
||||||
void AddCube(); // need a function to add new faces based on marching cubes surface
|
void LocalIsosurface(const DoubleArray A, double value, int i, int j, int k);
|
||||||
|
|
||||||
double origin(int edge);
|
double origin(int edge);
|
||||||
double EdgeAngle(int edge);
|
double EdgeAngle(int edge);
|
||||||
|
Loading…
Reference in New Issue
Block a user