Skip to content

Commit

Permalink
GUI completed with normalisation
Browse files Browse the repository at this point in the history
  • Loading branch information
DivyanshuSaxena committed Mar 20, 2018
1 parent d186f9f commit fcb36d1
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 29 deletions.
7 changes: 5 additions & 2 deletions include/Classes.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,16 @@ class Object3D {
bool rayCasting(Point,vector<Point>);
};

///
/// This class is an abstraction for a Wireframe Model that will be generated by projecting the three Orthographic views
///
class Wireframe {
public:
vector<Point> vertices;
vector<Edge> edges;
vector<vector<int> > adjacencyMatrix;
Wireframe* projectFrame();
int normalise();
int rotateFrame(int);
friend std::ostream& operator<< (std::ostream &out, const Wireframe &op) {
out << "Wireframe: " << std::endl << "Vertices: ";
Expand Down Expand Up @@ -222,5 +226,4 @@ class Projection2D {
int check2D();
int check3D();
Wireframe* input2Dfile(string filename);
PlaneProjection* input3Dfile(string filename);

PlaneProjection* input3Dfile(string filename);
1 change: 1 addition & 0 deletions include/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions src/Constructgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,12 @@ bool ConstructWindow::on_custom_draw(const Cairo::RefPtr<Cairo::Context>& 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 {
Expand Down
12 changes: 10 additions & 2 deletions src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"<<endl;
PlaneProjection* p = obj.project3D(planearr);
cout << "Object created from file: " << endl << obj << endl;
PlaneProjection* p = new PlaneProjection;
p = obj.project3D(planearr);
cout << "Projection: " << *p << endl;
p->rotatePlane();
cout << "Rotated Projection: " << *p << endl;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
25 changes: 22 additions & 3 deletions src/Projectgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -262,6 +262,25 @@ bool ProjectionWindow::on_custom_draw(const Cairo::RefPtr<Cairo::Context>& 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();
Expand All @@ -271,8 +290,8 @@ bool ProjectionWindow::on_custom_draw(const Cairo::RefPtr<Cairo::Context>& 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();
Expand Down
28 changes: 9 additions & 19 deletions src/Projection2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,37 @@ Wireframe Projection2D::create3D(){
cout << "lets start"<<endl;
allpoints = determineAllPoints();
cout <<"adjacencyMatrix point" <<endl;
printmatrix(adjacencyMatrix);
// cout << "allpoints detected and their number are "<< allpoints.size()<<endl;
// for(int i=0;i<allpoints.size();i++){
// cout << allpoints[i] << endl;
// cout << "i is "<< i<<endl;
// cout << "check if index to points map ======================================================================"<< endl;

// //cout << allpoints[i].label << " maps to "<< * (labeltopointmap[allpoints[i].label])<<endl;
// cout << allpoints[i].adjacencyIndex << " maps to "<< * (indextopointmap.at(i))<<endl;
// }
// printmatrix(adjacencyMatrix);

determineIntersectedEdges();
cout << "determineintersected edges complete "<< endl;
printmatrix(adjacencyMatrix);
// printmatrix(adjacencyMatrix);
cout << "execute corollary 1" <<endl;
executeCorollary1();
printmatrix(adjacencyMatrix);


// printmatrix(adjacencyMatrix);

cout << "corollary 1 finished chek3edge ==================================================="<< endl;
chkif3edgesanddefthem();
printmatrix(adjacencyMatrix);
// printmatrix(adjacencyMatrix);

cout<< "chek3edge finished loop starting==================================================="<< endl;
int numcountwhile = 0;
while(numofpossibleedge()!=0){
//function below checks if for a point a possible and definite point are collinear and removes the possible point
cout << "chekcollinearpossanddef started ================================================================" << endl;
bool ifcollinearpossanddef = chkcollinearpossanddef();
printmatrix(adjacencyMatrix);
// printmatrix(adjacencyMatrix);
cout << "chkcollinearpossandposs started ================================================================" <<endl;
bool ifcollinearpossandposs = chkcollinearpossandposs();
printmatrix(adjacencyMatrix);
// printmatrix(adjacencyMatrix);
cout << "chkposshasdefinanother started ================================================================" <<endl;

bool ifposshasdefinother = chkposshasdefinother();
printmatrix(adjacencyMatrix);
// printmatrix(adjacencyMatrix);
cout << "chk3dgesanddefthem started ================================================================" <<endl;

chkif3edgesanddefthem();
printmatrix(adjacencyMatrix);
// printmatrix(adjacencyMatrix);
numcountwhile++;
if(numcountwhile==50){
cout << "wrong answer"<<endl;
Expand Down
23 changes: 23 additions & 0 deletions src/Wireframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,29 @@
#include <math.h>
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;
Expand Down

0 comments on commit fcb36d1

Please sign in to comment.