-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTwoDModelGenerator.cpp
More file actions
77 lines (67 loc) · 2.19 KB
/
Copy pathTwoDModelGenerator.cpp
File metadata and controls
77 lines (67 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "TwoDModelGenerator.h"
TwoDModelGenerator::TwoDModelGenerator(ThreeDModel model){
this->model = model;
}
Point TwoDModelGenerator::_3Dto2DPoint(Point p, string plane){
Point _2DPoint = p;
if(plane == "xy" || plane == "yx"){
_2DPoint.setZ(0);
}
if(plane == "yz" || plane == "zy"){
_2DPoint.setX(0);
}
if(plane == "zx" || plane == "xz"){
_2DPoint.setY(0);
}
return _2DPoint;
}
Point* TwoDModelGenerator::_3Dto2DPoints(Point* pointArray, string plane, int arraySize){
Point* _2DPointsArray = (Point*)malloc (arraySize * sizeof(Point));
for (int i = 0; i < arraySize; i++){
Point _3DPoint = *pointArray;
Point _2DPoint = _3Dto2DPoint(_3DPoint, plane);
_2DPointsArray[i] = _2DPoint;
pointArray++;
}
return _2DPointsArray;
}
Line* TwoDModelGenerator::_3Dto2DLine(Line* lineArray, string plane, int arraySize){
Line* _2DLineArray = (Line*)malloc (arraySize * sizeof(Line));
for (int i = 0; i < arraySize; i++){
Line _3DLine = *lineArray;
Point _3Dp1 = _3DLine.getFirstPoint();
Point _3Dp2 = _3DLine.getSecondPoint();
Point _2Dp1 = _3Dto2DPoint(_3Dp1, plane);
Point _2Dp2 = _3Dto2DPoint(_3Dp2, plane);
Line _2DLine;
_2DLine.setFirstPoint(_2Dp1);
_2DLine.setSecondPoint(_2Dp2);
_2DLineArray[i] = _2DLine;
lineArray++;
}
return _2DLineArray;
}
TwoDModel TwoDModelGenerator::output(){
int pointSize = model.getPointSize();
int lineSize = model.getLineSize();
TwoDView xy;
xy.setPoints(_3Dto2DPoints(model.getPoints(),"xy",pointSize));
xy.setLines(_3Dto2DLine(model.getLines(),"xy",lineSize));
xy.setPointSize(pointSize);
xy.setLineSize(lineSize);
TwoDView yz;
yz.setPoints(_3Dto2DPoints(model.getPoints(),"yz",pointSize));
yz.setLines(_3Dto2DLine(model.getLines(),"yz",lineSize));
yz.setPointSize(pointSize);
yz.setLineSize(lineSize);
TwoDView zx;
zx.setPoints(_3Dto2DPoints(model.getPoints(),"zx",pointSize));
zx.setLines(_3Dto2DLine(model.getLines(),"zx",lineSize));
zx.setPointSize(pointSize);
zx.setLineSize(lineSize);
TwoDModel output;
output.setFrontView(xy);
output.setTopView(yz);
output.setSideView(zx);
return output;
}