Instrument Neutral Distributed Interface INDI
1.9.5
|
Go to the documentation of this file.
42 namespace AlignmentSubsystem
58 std::cerr <<
"AddOne: starting to add v" << p->
vnum <<
".\n";
68 std::cerr <<
"faddr: " << std::hex << f <<
" paddr: " << p <<
" Vol = " <<
std::dec << vol <<
'\n';
113 for (i = 0; i < 3; ++i)
120 std::cerr <<
"CheckEndpts: Error!\n";
121 std::cerr <<
" addr: " << std::hex <<
faces <<
':';
122 std::cerr <<
" edges:";
128 }
while (
faces != fstart);
131 std::cerr <<
"Checks: ERROR found and reported above.\n";
133 std::cerr <<
"Checks: All endpts of all edges of all faces check.\n";
139 std::cerr <<
"Checks: V, E, F = " << V <<
' ' << E <<
' ' << F <<
":\t";
141 if ((V - E + F) != 2)
142 std::cerr <<
"Checks: V-E+F != 2\n";
144 std::cerr <<
"V-E+F = 2\t";
146 if (F != (2 * V - 4))
147 std::cerr <<
"Checks: F=" << F <<
" != 2V-4=" << 2 * V - 4 <<
"; V=" << V <<
'\n';
149 std::cerr <<
"F = 2V-4\t";
151 if ((2 * E) != (3 * F))
152 std::cerr <<
"Checks: 2E=" << 2 * E <<
" != 3F=" << 3 * F <<
"; E=" << E <<
", F=" << F <<
'\n';
154 std::cerr <<
"2E = 3F\n";
162 int V = 0, E = 0, F = 0;
174 if ((e =
edges) !=
nullptr)
179 }
while (e !=
edges);
180 if ((f =
faces) !=
nullptr)
185 }
while (f !=
faces);
209 }
while (e !=
edges);
215 remove<tEdge>(
edges, e);
224 remove<tEdge>(
edges, t);
228 }
while (e !=
edges);
239 remove<tFace>(
faces, f);
248 remove<tFace>(
faces, t);
252 }
while (f !=
faces);
273 }
while (e !=
edges);
312 return (c->
v[
Z] - a->
v[
Z]) * (b->
v[
Y] - a->
v[
Y]) - (b->
v[
Z] - a->
v[
Z]) * (c->
v[
Y] - a->
v[
Y]) == 0 &&
313 (b->
v[
Z] - a->
v[
Z]) * (c->
v[
X] - a->
v[
X]) - (b->
v[
X] - a->
v[
X]) * (c->
v[
Z] - a->
v[
Z]) == 0 &&
314 (b->
v[
X] - a->
v[
X]) * (c->
v[
Y] - a->
v[
Y]) - (b->
v[
Y] - a->
v[
Y]) * (c->
v[
X] - a->
v[
X]) == 0;
339 }
while (e !=
edges);
342 std::cerr <<
"Checks: edges are NOT consistent.\n";
344 std::cerr <<
"Checks: edges consistent.\n";
363 std::cerr <<
"ConstructHull: After Add of " << v->
vnum <<
" & Cleanup:\n";
397 }
while (f !=
faces);
400 std::cerr <<
"Checks: NOT convex.\n";
402 std::cerr <<
"Checks: convex.\n";
408 tFace f0, f1 =
nullptr;
416 std::cout <<
"DoubleTriangle: All points are Collinear!\n";
444 if ((v3 = v3->
next) == v0)
446 std::cout <<
"DoubleTriangle: All points are coplanar!\n";
456 std::cerr <<
"DoubleTriangle: finished. Head repositioned at v3.\n";
469 for (i = 0; i < 3; i++)
475 for (j = 0; j < 3; j++)
484 std::cerr <<
"Making a swap in EdgeOrderOnFaces: F(" << f->
vertex[0]->
vnum <<
','
487 newEdge = f->
edge[i];
489 f->
edge[j] = newEdge;
495 }
while (f !=
faces);
523 swap<tEdge>(s, f->
edge[1], f->
edge[2]);
539 for (i = 0; i < 2; ++i)
546 new_edge[i]->
endpts[1] = p;
552 new_face->
edge[0] = e;
553 new_face->
edge[1] = new_edge[0];
554 new_face->
edge[2] = new_edge[1];
558 for (i = 0; i < 2; ++i)
559 for (j = 0; j < 2; ++j)
561 if (!new_edge[i]->adjface[j])
563 new_edge[i]->
adjface[j] = new_face;
615 v->
v[
X] = x * ScaleFactor;
616 v->
v[
Y] = y * ScaleFactor;
617 v->
v[
Z] = z * ScaleFactor;
619 if ((std::abs(x) >
SAFE) || (std::abs(y) >
SAFE) || (std::abs(z) >
SAFE))
621 std::cout <<
"Coordinate of vertex below might be too large: run with -d flag\n";
634 add<tEdge>(
edges, e);
643 for (
int i = 0; i < 3; ++i)
645 f->
edge[i] =
nullptr;
649 add<tFace>(
faces, f);
672 int xmin, ymin, xmax, ymax;
675 int V = 0, E = 0, F = 0;
680 xmin = xmax = v->
v[
X];
685 else if (v->
v[
X] < xmin)
692 ymin = ymax = v->
v[
Y];
697 else if (v->
v[
Y] < ymin)
703 std::cout <<
"%!PS\n";
704 std::cout <<
"%%BoundingBox: " << xmin <<
' ' << ymin <<
' ' << xmax <<
' ' << ymax <<
'\n';
705 std::cout <<
".00 .00 setlinewidth\n";
706 std::cout << -xmin + 72 <<
' ' << -ymin + 72 <<
" translate\n";
717 std::cout <<
"\n%% Vertices:\tV = " << V <<
'\n';
718 std::cout <<
"%% index:\t\tx\ty\tz\n";
721 std::cout <<
"%% " << v->
vnum <<
":\t" << v->
v[
X] <<
'\t' << v->
v[
Y] <<
'\t' << v->
v[
Z] <<
'\n';
732 }
while (f !=
faces);
733 std::cout <<
"\n%% Faces:\tF = " << F <<
'\n';
734 std::cout <<
"%% Visible faces only: \n";
742 if ((a[0] * b[1] - a[1] * b[0]) >= 0)
746 std::cout <<
"newpath\n";
747 std::cout << f->
vertex[0]->
v[
X] <<
'\t' << f->
vertex[0]->
v[
Y] <<
"\tmoveto\n";
748 std::cout << f->
vertex[1]->
v[
X] <<
'\t' << f->
vertex[1]->
v[
Y] <<
"\tlineto\n";
749 std::cout << f->
vertex[2]->
v[
X] <<
'\t' << f->
vertex[2]->
v[
Y] <<
"\tlineto\n";
750 std::cout <<
"closepath stroke\n\n";
753 }
while (f !=
faces);
756 std::cout <<
"%% List of all faces: \n";
757 std::cout <<
"%%\tv0\tv1\tv2\t(vertex indices)\n";
762 }
while (f !=
faces);
770 }
while (e !=
edges);
771 std::cout <<
"\n%% Edges:\tE = " << E <<
'\n';
774 std::cout <<
"\nshowpage\n\n";
786 Ofile <<
"Edge List\n";
790 Ofile <<
" addr: " << std::hex <<
edges <<
'\t';
792 for (i = 0; i < 2; ++i)
795 for (i = 0; i < 2; ++i)
799 }
while (
edges != temp);
808 Ofile <<
"Face List\n";
812 Ofile <<
" addr: " << std::hex <<
faces <<
" ";
813 Ofile <<
" edges:" << std::hex;
814 for (i = 0; i < 3; ++i)
817 for (i = 0; i < 3; ++i)
821 }
while (
faces != temp);
828 std::map<int, int> vnumToOffsetMap;
833 Ofile.open(FileName, std::ios_base::out | std::ios_base::trunc);
835 Ofile <<
"# obj file written by chull\n";
836 Ofile <<
"mtllib chull.mtl\n";
837 Ofile <<
"g Object001\n";
839 Ofile <<
"usemtl default\n";
848 vnumToOffsetMap[v->
vnum] = Offset;
849 Ofile <<
"v " << v->
v[
X] <<
' ' << v->
v[
Y] <<
' ' << v->
v[
Z] <<
'\n';
863 c[0] = a[1] * b[2] - a[2] * b[1];
864 c[1] = a[2] * b[0] - a[0] * b[2];
865 c[2] = a[0] * b[1] - a[1] * b[0];
867 length = sqrt((c[0] * c[0]) + (c[1] * c[1]) + (c[2] * c[2]));
868 c[0] = c[0] / length;
869 c[1] = c[1] / length;
870 c[2] = c[2] / length;
871 Ofile <<
"vn " << c[0] <<
' ' << c[1] <<
' ' << c[2] <<
'\n';
873 }
while (f !=
faces);
880 Ofile <<
"f " << vnumToOffsetMap[f->
vertex[0]->
vnum] <<
"//" << i <<
' ' << vnumToOffsetMap[f->
vertex[1]->
vnum]
881 <<
"//" << i <<
' ' << vnumToOffsetMap[f->
vertex[2]->
vnum] <<
"//" << i <<
'\n';
884 }
while (f !=
faces);
888 Ofile.open(
"chull.mtl", std::ios_base::out | std::ios_base::trunc);
890 Ofile <<
"newmtl default\n";
891 Ofile <<
"Ka 0.2 0 0\n";
892 Ofile <<
"Kd 0.8 0 0\n";
893 Ofile <<
"illum 1\n";
901 Ofile.open(FileName, std::ios_base::out | std::ios_base::trunc);
903 Ofile <<
"\nHead vertex " << v->
vnum <<
" = " << std::hex << v <<
" :\n";
914 for (
int i = 0; i < 3; i++)
915 std::cout <<
'\t' << p->
v[i];
925 Ofile <<
"Vertex List\n";
929 Ofile <<
" addr " << std::hex <<
vertices <<
"\t";
945 while (!(std::cin.eof() || std::cin.fail()))
947 std::cin >> x >> y >> z;
953 if ((abs(x) >
SAFE) || (abs(y) >
SAFE) || (abs(z) >
SAFE))
955 std::cout <<
"Coordinate of vertex below might be too large: run with -d flag\n";
967 if (
nullptr != CurrentVertex)
971 tVertex TempVertex = CurrentVertex;
972 CurrentVertex = CurrentVertex->
next;
974 }
while (CurrentVertex !=
vertices);
978 if (
nullptr != CurrentEdge)
982 tEdge TempEdge = CurrentEdge;
983 CurrentEdge = CurrentEdge->
next;
985 }
while (CurrentEdge !=
edges);
989 if (
nullptr != CurrentFace)
993 tFace TempFace = CurrentFace;
994 CurrentFace = CurrentFace->
next;
996 }
while (CurrentFace !=
faces);
1008 for (i = 0; i < 3; i++)
1016 int ax, ay, az, bx, by, bz, cx, cy, cz;
1028 vol = (ax * (by * cz - bz * cy) + ay * (bz * cx - bx * cz) + az * (bx * cy - by * cx));
1037 double ax, ay, az, bx, by, bz, cx, cy, cz;
1049 vol = ax * (by * cz - bz * cy) + ay * (bz * cx - bx * cz) + az * (bx * cy - by * cx);
1055 std::cerr <<
"Face=" << std::hex << f <<
"; Vertex=" <<
std::dec << p->
vnum <<
": vol(int) = " << voli
1056 <<
", vol(double) = " << vol <<
"\n";
1062 else if (vol < -0.5)
bool Collinear(tVertex a, tVertex b, tVertex c)
Collinear checks to see if the three points given are collinear, by checking to see if each element o...
void ReadVertices()
ReadVertices: Reads in the vertices, and links them into a circular list with MakeNullVertex....
void ConstructHull()
ConstructHull adds the vertices to the hull one at a time. The hull vertices are those in the list ma...
void PrintObj(const char *FileName="chull.obj")
Outputs the faces in Lightwave obj format for 3d viewing. The files chull.obj and chull....
void Print()
Print: Prints out the vertices and the faces. Uses the vnum indices corresponding to the order in whi...
void SubVec(int a[3], int b[3], int c[3])
SubVec: Computes a - b and puts it into c.
void MakeNewVertex(double x, double y, double z, int VertexId)
Makes a vertex from the supplied information and adds it to the vertices list.
tFace MakeFace(tVertex v0, tVertex v1, tVertex v2, tFace f)
MakeFace creates a new face structure from three vertices (in ccw order). It returns a pointer to the...
void MakeCcw(tFace f, tEdge e, tVertex p)
MakeCcw puts the vertices in the face structure in counterclock wise order. We want to store the vert...
void CheckEndpts()
Checks that, for each face, for each i={0,1,2}, the [i]th vertex of that face is either the [0]th or ...
tFace MakeConeFace(tEdge e, tVertex p)
MakeConeFace makes a new face and two new edges between the edge and the point that are passed to it....
int Volumei(tFace f, tVertex p)
Volumei returns the volume of the tetrahedron determined by f and p.
static const bool PROCESSED
tEdge MakeNullEdge()
MakeNullEdge creates a new cell and initializes all pointers to NULL and sets all flags to off....
void Reset()
Frees the vertices edges and faces lists and resets the debug and check flags.
bool AddOne(tVertex p)
AddOne is passed a vertex. It first determines all faces visible from that point. If none are visible...
int VolumeSign(tFace f, tVertex p)
VolumeSign returns the sign of the volume of the tetrahedron determined by f and p....
void CleanUp(tVertex *pvnext)
CleanUp goes through each data structure list and clears all flags and NULLs out some pointers....
tFace MakeNullFace()
MakeNullFace creates a new face structure and initializes all of its flags to NULL and sets all the f...
void EdgeOrderOnFaces()
EdgeOrderOnFaces: puts e0 between v0 and v1, e1 between v1 and v2, e2 between v2 and v0 on each face....
void CleanVertices(tVertex *pvnext)
CleanVertices runs through the vertex list and deletes the vertices that are marked as processed but ...
void CleanFaces()
CleanFaces runs through the face list and deletes any face marked visible.
void Checks()
Checks the consistency of the hull and prints the results to the standard error output.
struct tEdgeStructure tsEdge
void PrintPoint(tVertex p)
Prints a single vertex to the standard output.
static const bool VISIBLE
void DoubleTriangle()
DoubleTriangle builds the initial double triangle. It first finds 3 noncollinear points and makes two...
void CheckEuler(int V, int E, int F)
CheckEuler checks Euler's relation, as well as its implications when all faces are known to be triang...
void PrintEdges(std::ofstream &Ofile)
Prints the edges Ofile.
void PrintVertices(std::ofstream &Ofile)
Prints vertices to Ofile.
void Consistency()
Consistency runs through the edge list and checks that all adjacent faces have their endpoints in opp...
void PrintFaces(std::ofstream &Ofile)
Prints the faces to Ofile.
Namespace to encapsulate INDI client, drivers, and mediator classes.
void CleanEdges()
CleanEdges runs through the edge list and cleans up the structure. If there is a newface then it will...
void Convexity()
Convexity checks that the volume between every face and every point is negative. This shows that each...
void PrintOut(const char *FileName, tVertex v)
Prints vertices, edges and faces to the standard error output.
struct tFaceStructure tsFace
static const bool REMOVED
tVertex MakeNullVertex()
MakeNullVertex: Makes a vertex, nulls out fields.
struct tVertexStructure tsVertex