Skip to content

Commit f083d12

Browse files
committed
Changes to test area
1 parent a8b070b commit f083d12

File tree

5 files changed

+105
-107
lines changed

5 files changed

+105
-107
lines changed

area.cpp

+9-41
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,15 @@ double areaTrapezoid(double l1, double l2, double l3, double l4) {
1616
l2 = l3;
1717
l3 = temp;
1818
}
19-
area = (l2+l3) / (4 * (l2-l3));
20-
temp = (l2 + l1 - l3 + l4) * (l2 - l1 - l3 + l4) * (l2 + l1 - l3 - l4) * (-l2 + l1 + l3 + l4);
21-
area = area * sqrt(temp);
19+
double temp1 = (l2 + l1 - l3 + l4);
20+
double temp2 = (l2 - l1 - l3 + l4);
21+
double temp3 = (l2 + l1 - l3 - l4);
22+
double temp4 = (-l2 + l1 + l3 + l4);
23+
if (abs(temp1*temp2*temp3*temp4) < 0.00001) {
24+
qDebug() << "Area is less than 0";
25+
}
26+
area = sqrt(temp1*temp2*temp3*temp4);
27+
area = area*(l2+l3)/(4*(l2-l3));
2228
return area;
2329
}
2430

@@ -29,42 +35,4 @@ double areaTriangle(double l1, double l2, double l3) {
2935
area = sqrt(area);
3036
return area;
3137
}
32-
double chestArea(Vertex minx, Vertex maxx, QVector<QPair<Vertex, Vertex>> sliceSegments) {
33-
double area = 0.0;
34-
35-
for (long i = 0; i < sliceSegments.size(); ++i) {
36-
Vertex slice_v1 = sliceSegments[i].first;
37-
Vertex slice_v2 = sliceSegments[i].second;
38-
39-
double slope = (minx.x - maxx.x) / (minx.y - maxx.y);
40-
double z_v1 = slope * (slice_v1.x - maxx.x) + maxx.y;
41-
double z_v2 = slope * (slice_v2.x - maxx.x) + maxx.y;
42-
43-
//Size of the segment on the chest
44-
double line1 = distance(slice_v1.x, slice_v1.z, slice_v2.x, slice_v2.z);
45-
//From vertex on the chest to the horizontal line
46-
double line2 = distance(slice_v1.x, slice_v1.z, slice_v1.x, z_v1);
47-
double line3 = distance(slice_v2.x, slice_v2.z, slice_v2.x, z_v2);
48-
//length on the horizontal line
49-
double line4 = distance(slice_v1.x, z_v1, slice_v2.x, z_v2);
50-
51-
double temp_area = areaTrapezoid(line1, line2, line3, line4);
52-
area += temp_area;
53-
}
54-
return area;
55-
}
56-
57-
double defectArea(Vertex v1, Vertex v2, QVector<QPair<Vertex, Vertex>> defectSegments) {
58-
double area = 0.0;
59-
double x = (v1.x + v2.x) / 2;
60-
double y = (v1.y + v2.y) / 2;
6138

62-
for (int i = 0; i < defectSegments.size(); ++i) {
63-
double l1 = distance(x, defectSegments[i].first.x, y, defectSegments[i].first.y);
64-
double l2 = distance(x, defectSegments[i].second.x, y, defectSegments[i].second.y);
65-
double l3 = distance(defectSegments[i].second.x, defectSegments[i].first.x,
66-
defectSegments[i].second.y, defectSegments[i].first.y);
67-
area += areaTriangle(l1, l2, l3);
68-
}
69-
return area;
70-
}

area.h

-3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@
66
#include <QtMath>
77
#include <QDebug>
88
#include <QFile>
9-
#include "pectusprocessor.h"
109

1110
double distance(double x1, double x2, double y1, double y2);
1211
double areaTrapezoid(double l1, double l2, double l3, double l4);
1312
double areaTriangle(double l1, double l2, double l3);
14-
double defectArea(Vertex v1, Vertex v2, QVector<QPair<Vertex, Vertex>> defectSegments);
15-
double chestArea(Vertex minx, Vertex maxx, QVector<QPair<Vertex, Vertex>> sliceSegments);
1613

1714
#endif // AREA_H

main.qml

+50-39
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,19 @@ ApplicationWindow {
297297
}
298298
}
299299

300+
Rectangle {
301+
id: indiceBox
302+
anchors.top: renderScanButton.bottom
303+
304+
Text {
305+
id: hallerText
306+
visible: myProcessor.hallerIndexVisible
307+
text: "Haller Index: " + myProcessor.hallerIndex
308+
anchors.top: indiceBox.top
309+
anchors.topMargin: 10
310+
}
311+
}
312+
300313
FileDialog {
301314
id: fileDialog
302315
title: "Choose a 3D Model File"
@@ -333,6 +346,43 @@ ApplicationWindow {
333346
anchors.rightMargin: 20
334347

335348
height: 300
349+
Row {
350+
id: indexButtonRow
351+
anchors.bottom: sliceButtonRow.top
352+
anchors.bottomMargin: 5
353+
spacing: 3
354+
Button {
355+
id: hallerIndex
356+
text: "Haller Index"
357+
onClicked: {
358+
myProcessor.calculateHallerIndex();
359+
}
360+
}
361+
Button {
362+
id: defectLine
363+
text: "Defect"
364+
onClicked: {
365+
myProcessor.findDefectPoint();
366+
}
367+
}
368+
Button {
369+
id:fixedIntersection
370+
text: "Fixed"
371+
onClicked: {
372+
myProcessor.getFixedIntersection();
373+
console.log("Drawing fixed intersection");
374+
myProcessor.drawLineSegments();
375+
}
376+
}
377+
Button {
378+
id: chestArea
379+
text: "Area"
380+
onClicked: {
381+
myProcessor.chestArea();
382+
383+
}
384+
}
385+
}
336386

337387
Row {
338388
id: sliceButtonRow
@@ -377,45 +427,6 @@ ApplicationWindow {
377427
myProcessor.eraseArms(sliceCanvas.width, sliceCanvas.height)
378428
}
379429
}
380-
Button {
381-
id: hallerIndex
382-
text: "Haller Index"
383-
onClicked: {
384-
myProcessor.calculateHallerIndex();
385-
}
386-
}
387-
Button {
388-
id: defectLine
389-
text: "Defect"
390-
onClicked: {
391-
myProcessor.findDefectPoint();
392-
}
393-
}
394-
Button {
395-
id:fixedIntersection
396-
text: "Fixed"
397-
onClicked: {
398-
myProcessor.getFixedIntersection();
399-
console.log("Drawing fixed intersection");
400-
myProcessor.drawLineSegments();
401-
}
402-
}
403-
Button {
404-
id: chestArea
405-
text: "Area"
406-
onClicked: {
407-
408-
}
409-
}
410-
411-
}
412-
Text {
413-
id: hallerText
414-
visible: myProcessor.hallerIndexVisible
415-
text: "Haller Index: " + myProcessor.hallerIndex
416-
anchors.right: sliceButtonRow.right
417-
anchors.bottom: sliceButtonRow.top
418-
anchors.topMargin: 10
419430
}
420431

421432
SliceCanvas {

pectusprocessor.cpp

+41-24
Original file line numberDiff line numberDiff line change
@@ -712,30 +712,47 @@ QVector<QPair<Vertex,Vertex>> PectusProcessor::findLargestSet(){
712712
return connected;
713713
}
714714

715-
using namespace QtDataVisualization;
716-
void PectusProcessor::createSurfaceModel(const QVector<Vertex> & vertices, const QVector<Face> & faces) {
717-
int i = 0;
718-
QSurfaceDataArray *model_data = new QSurfaceDataArray;
719-
while (i < faces.size()){
720-
float v1x = vertices[faces[i].vertex1Index].x;
721-
float v1y = vertices[faces[i].vertex1Index].y;
722-
float v1z = vertices[faces[i].vertex1Index].z;
723-
float v2x = vertices[faces[i].vertex2Index].x;
724-
float v2y = vertices[faces[i].vertex2Index].y;
725-
float v2z = vertices[faces[i].vertex2Index].z;
726-
float v3x = vertices[faces[i].vertex3Index].x;
727-
float v3y = vertices[faces[i].vertex3Index].y;
728-
float v3z = vertices[faces[i].vertex3Index].z;
729-
730-
QSurfaceDataRow * face = new QSurfaceDataRow;
731-
QVector3D * v1 = new QVector3D(v1x, v1y, v1z);
732-
QVector3D * v2 = new QVector3D(v2x, v2y, v2z);
733-
QVector3D * v3 = new QVector3D(v3x, v3y, v3z);
734-
735-
*face << *v1 << *v2 << *v3;
736-
*model_data << face;
715+
double PectusProcessor::chestArea() {
716+
double area = 0.0;
717+
for (long i = 0; i < sliceSegments.size(); ++i) {
718+
Vertex slice_v1 = sliceSegments[i].first;
719+
Vertex slice_v2 = sliceSegments[i].second;
720+
721+
double slope = (minx.z - maxx.z) / (minx.x - maxx.x);
722+
723+
double z_v1 = slope * (slice_v1.x - maxx.x) + maxx.z;
724+
double z_v2 = slope * (slice_v2.x - maxx.x) + maxx.z;
725+
726+
//qDebug() << slope << z_v1 << z_v2;
727+
//Size of the segment on the chest
728+
double line1 = distance(slice_v1.x, slice_v1.z, slice_v2.x, slice_v2.z);
729+
//From vertex on the chest to the horizontal line
730+
double line2 = distance(slice_v1.x, slice_v1.z, slice_v1.x, z_v1);
731+
double line3 = distance(slice_v2.x, slice_v2.z, slice_v2.x, z_v2);
732+
//length on the horizontal line
733+
double line4 = distance(slice_v1.x, z_v1, slice_v2.x, z_v2);
734+
735+
qDebug() << line1 << line2 << line3 << line4;
736+
737+
double temp_area = areaTrapezoid(line1, line2, line3, line4);
738+
//qDebug() << temp_area;
739+
area += temp_area;
737740
}
738-
// need to bind this data to a surface like:
739-
//model_surface->resetArray(model_data);
741+
qDebug() << "Chest Area: " << area;
742+
return area;
740743
}
741744

745+
double PectusProcessor::defectArea(Vertex v1, Vertex v2, QVector<QPair<Vertex, Vertex>> defectSegments) {
746+
double area = 0.0;
747+
double x = (v1.x + v2.x) / 2;
748+
double y = (v1.y + v2.y) / 2;
749+
750+
for (int i = 0; i < defectSegments.size(); ++i) {
751+
double l1 = distance(x, defectSegments[i].first.x, y, defectSegments[i].first.y);
752+
double l2 = distance(x, defectSegments[i].second.x, y, defectSegments[i].second.y);
753+
double l3 = distance(defectSegments[i].second.x, defectSegments[i].first.x,
754+
defectSegments[i].second.y, defectSegments[i].first.y);
755+
area += areaTriangle(l1, l2, l3);
756+
}
757+
return area;
758+
}

pectusprocessor.h

+5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <QtDataVisualization/QSurface3DSeries>
1212
#include <QtWidgets/QSlider>
1313
#include <cmath>
14+
#include "area.h"
1415

1516
struct Vertex {
1617
double x,y,z;
@@ -67,6 +68,8 @@ class PectusProcessor : public QObject
6768
Q_INVOKABLE bool getHallerIndexVisible();
6869
Q_INVOKABLE void calculateHallerIndex();
6970
Q_INVOKABLE void getFixedIntersection();
71+
Q_INVOKABLE double chestArea();
72+
Q_INVOKABLE double defectArea(Vertex v1, Vertex v2, QVector<QPair<Vertex, Vertex>> defectSegments);
7073

7174
// Erases arms that are completely disconnected from the drawing
7275
Q_INVOKABLE void eraseArms(int canvasWidth, int canvasHeight);
@@ -129,6 +132,8 @@ class PectusProcessor : public QObject
129132
void fileNameChanged(const QString & arg);
130133
void hallerIndexChanged(const double & arg);
131134
void hallerIndexVisibleChanged(const bool arg);
135+
void volumeDefectIndexChanged(const double & arg);
136+
void volumeDefectIndexVisibleChanged(const bool arg);
132137

133138
public slots:
134139

0 commit comments

Comments
 (0)