diff --git a/include/Classes.h b/include/Classes.h index 42fb389..b06c049 100644 --- a/include/Classes.h +++ b/include/Classes.h @@ -166,12 +166,16 @@ class Object3D { bool rayCasting(Point,vector); }; +/// +/// This class is an abstraction for a Wireframe Model that will be generated by projecting the three Orthographic views +/// class Wireframe { public: vector vertices; vector edges; vector > adjacencyMatrix; Wireframe* projectFrame(); + int normalise(); int rotateFrame(int); friend std::ostream& operator<< (std::ostream &out, const Wireframe &op) { out << "Wireframe: " << std::endl << "Vertices: "; @@ -222,5 +226,4 @@ class Projection2D { int check2D(); int check3D(); Wireframe* input2Dfile(string filename); -PlaneProjection* input3Dfile(string filename); - +PlaneProjection* input3Dfile(string filename); \ No newline at end of file diff --git a/include/gui.h b/include/gui.h index 1c41a95..31c8f62 100644 --- a/include/gui.h +++ b/include/gui.h @@ -68,6 +68,7 @@ class ConstructWindow : public Gtk::Window int projection, create; OrthoProjection* front, * top, * side; ClusteredPoint* cp; + double factor; // Child widgets: Gtk::Box m_Box; diff --git a/src/Constructgui.cpp b/src/Constructgui.cpp index 640fab5..a7b0e52 100644 --- a/src/Constructgui.cpp +++ b/src/Constructgui.cpp @@ -311,11 +311,12 @@ bool ConstructWindow::on_custom_draw(const Cairo::RefPtr& cr) Vector3d p1(obj->edges[0].p1.x,obj->edges[0].p1.y,obj->edges[0].p1.z); Vector3d p2(obj->edges[0].p2.x,obj->edges[0].p2.y,obj->edges[0].p2.z); double dist = (p1-p2).norm(); - double factor = (width/dist)/5; + if(factor==0) + factor = (width/dist)/5; for(int i = 0; i < obj->edges.size(); i++) { // cout << obj->edges[i].p1.x << " " << obj->edges[i].p1.y << endl; - cr->move_to((obj->edges[i].p1.x)*100 + xc, (obj->edges[i].p1.y)*100 + yc); - cr->line_to((obj->edges[i].p2.x)*100 + xc, (obj->edges[i].p2.y)*100 + yc); + cr->move_to((obj->edges[i].p1.x)*factor + xc, (obj->edges[i].p1.y)*factor + yc); + cr->line_to((obj->edges[i].p2.x)*factor + xc, (obj->edges[i].p2.y)*factor + yc); } cr->stroke(); } else { diff --git a/src/Main.cpp b/src/Main.cpp index 600a487..def3b48 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -176,10 +176,12 @@ PlaneProjection* input3Dfile(string filename){ planearr[2]=n3; planearr[3]=n4; } - cout << "plane finished" << endl; + // cout << "plane finished" << endl; } cout << "file complete"<rotatePlane(); cout << "Rotated Projection: " << *p << endl; @@ -509,6 +511,9 @@ Wireframe* input2Dfile(string filename){ edge.p2.setCoordinates(frame.edges[i].p2.x,frame.edges[i].p2.y,frame.edges[i].p2.z); retFrame->edges.push_back(edge); } + // cout << "retFrame: " << *retFrame << endl; + retFrame->normalise(); + // cout << "retFrame after normalise: " << endl << *retFrame << endl; return retFrame; } return 0; @@ -557,5 +562,8 @@ Wireframe* createProjection(Projection2D* projection) { edge.p2.setCoordinates(newFrame.edges[i].p2.x,newFrame.edges[i].p2.y,newFrame.edges[i].p2.z); retFrame->edges.push_back(edge); } + // cout << "retFrame: " << *retFrame << endl; + retFrame->normalise(); + // cout << "retFrame after normalise: " << endl << *retFrame << endl; return retFrame; } \ No newline at end of file diff --git a/src/Projectgui.cpp b/src/Projectgui.cpp index 10fa405..5225be2 100644 --- a/src/Projectgui.cpp +++ b/src/Projectgui.cpp @@ -120,7 +120,7 @@ ProjectionWindow::ProjectionWindow() // Add Drawing Area m_Box.pack_start(m_draw_frame, Gtk::PACK_EXPAND_WIDGET, 10); - m_area.set_size_request(600,400); + m_area.set_size_request(600,500); m_draw_frame.add(m_area); // Signal Handlers @@ -262,6 +262,25 @@ bool ProjectionWindow::on_custom_draw(const Cairo::RefPtr& cr) cr->set_source_rgb(0.0, 0.0, 0.0); if(this->create) { + double sumx = 0.0; + double sumy = 0.0; + int len = output->visibleEdges.size() + output->hiddenEdges.size(); + for(int i = 0; i < len; i++) { + if(i < output->visibleEdges.size()) { + sumx += output->visibleEdges[i].p1.x; + sumx += output->visibleEdges[i].p2.x; + sumy += output->visibleEdges[i].p1.y; + sumy += output->visibleEdges[i].p2.y; + } else { + sumx += output->hiddenEdges[i].p1.x; + sumx += output->hiddenEdges[i].p1.x; + sumx += output->hiddenEdges[i].p1.x; + sumx += output->hiddenEdges[i].p1.x; + } + } + sumx = sumx/(len); + sumy = sumy/(len); + cout << sumx << " " << sumy << endl; Vector3d p1(output->visibleEdges[0].p1.x,output->visibleEdges[0].p1.y,output->visibleEdges[0].p1.z); Vector3d p2(output->visibleEdges[0].p2.x,output->visibleEdges[0].p2.y,output->visibleEdges[0].p2.z); double dist = (p1-p2).norm(); @@ -271,8 +290,8 @@ bool ProjectionWindow::on_custom_draw(const Cairo::RefPtr& cr) vec.push_back(5.0); cr->set_dash(vec,0); for(int i = 0; i < output->hiddenEdges.size(); i++) { - cr->move_to((output->hiddenEdges[i].p1.x)*factor + xc, (output->hiddenEdges[i].p1.y)*factor + yc); - cr->line_to((output->hiddenEdges[i].p2.x)*factor + xc, (output->hiddenEdges[i].p2.y)*factor + yc); + cr->move_to((output->hiddenEdges[i].p1.x)*factor + xc - sumx, (output->hiddenEdges[i].p1.y)*factor + yc - sumy); + cr->line_to((output->hiddenEdges[i].p2.x)*factor + xc - sumx, (output->hiddenEdges[i].p2.y)*factor + yc - sumy); } cr->stroke(); cr->restore(); diff --git a/src/Projection2D.cpp b/src/Projection2D.cpp index 9c89942..67b1e11 100644 --- a/src/Projection2D.cpp +++ b/src/Projection2D.cpp @@ -8,28 +8,18 @@ Wireframe Projection2D::create3D(){ cout << "lets start"< using namespace Eigen; +int Wireframe::normalise() { + double sumx = 0.0; + double sumy = 0.0; + double sumz = 0.0; + for(int i = 0; i < this->vertices.size(); i++) { + sumx += this->vertices[i].x; + sumy += this->vertices[i].y; + sumz += this->vertices[i].z; + } + sumx = sumx/(this->vertices.size()); + sumy = sumy/(this->vertices.size()); + sumz = sumz/(this->vertices.size()); + for(int i = 0; i < this->edges.size(); i++) { + this->edges[i].p1.x -= sumx; + this->edges[i].p1.y -= sumy; + this->edges[i].p1.z -= sumz; + this->edges[i].p2.x -= sumx; + this->edges[i].p2.y -= sumy; + this->edges[i].p2.z -= sumz; + } + return 0; +} + Wireframe* Wireframe::projectFrame() { double plane[4] = {0,0,1,0}; Wireframe* projected;