50 const QSharedPointer<DistanceMapGenerationTool::Map>& map,
53 unsigned angularStepCount,
63 if (!map || !
profile || angularStepCount == 0 || heightStep <= 0) {
70 profile->getAssociatedCloud()->getBoundingBox(profileBBMin, profileBBMax);
73 static_cast<double>(profileBBMin.
y) + heightShift);
74 double yMax =
std::min(map->yMin + map->ySteps * map->yStep,
75 static_cast<double>(profileBBMax.
y) + heightShift);
76 const double ySpan = yMax - yMin;
78 const double xMin = profileBBMin.
x;
80 const double xSpan = profileBBMax.
x - profileBBMin.
x;
82 if (xSpan == 0.0 && ySpan == 0.0) {
90 DL_WriterA* dw = dxf.out(qPrintable(
filename), DL_VERSION_R12);
93 app->
dispToConsole(QString(
"Failed to open '%1' file for writing!")
100 dxf.writeHeader(*dw);
103 dw->dxfString(9,
"$INSBASE");
104 dw->dxfReal(10, 0.0);
105 dw->dxfReal(20, 0.0);
106 dw->dxfReal(30, 0.0);
107 dw->dxfString(9,
"$EXTMIN");
108 dw->dxfReal(10, 0.0);
109 dw->dxfReal(20, 0.0);
110 dw->dxfReal(30, 0.0);
111 dw->dxfString(9,
"$EXTMAX");
114 dw->dxfReal(30, 0.0);
115 dw->dxfString(9,
"$LIMMIN");
116 dw->dxfReal(10, 0.0);
117 dw->dxfReal(20, 0.0);
118 dw->dxfString(9,
"$LIMMAX");
132 dw->tableLinetypes(3);
133 dxf.writeLinetype(*dw,
134 DL_LinetypeData(
"BYBLOCK",
"BYBLOCK", 0, 0, 0.0));
135 dxf.writeLinetype(*dw,
136 DL_LinetypeData(
"BYLAYER",
"BYLAYER", 0, 0, 0.0));
138 *dw, DL_LinetypeData(
"CONTINUOUS",
"Continuous", 0, 0, 0.0));
143 dw->tableLayers(angularStepCount + 3);
144 QStringList profileNames;
147 dxf.writeLayer(*dw, DL_LayerData(
"0", 0),
148 DL_Attributes(std::string(
""),
166 for (
unsigned i = 0; i < angularStepCount; ++i) {
179 profileNames << layerName;
182 DL_LayerData(qPrintable(layerName),
185 DL_Attributes(std::string(
""),
197 dxf.writeStyle(*dw, DL_StyleData(
"Standard", 0, 0.0, 0.75, 0.0, 0, 2.5,
205 dw->tableAppidEntry(0x12);
206 dw->dxfString(2,
"ACAD");
211 dxf.writeDimStyle(*dw,
219 dxf.writeBlockRecord(*dw);
231 dxf.writeBlock(*dw, DL_BlockData(
"*Model_Space", 0, 0.0, 0.0, 0.0));
232 dxf.writeEndBlock(*dw,
"*Model_Space");
234 dxf.writeBlock(*dw, DL_BlockData(
"*Paper_Space", 0, 0.0, 0.0, 0.0));
235 dxf.writeEndBlock(*dw,
"*Paper_Space");
237 dxf.writeBlock(*dw, DL_BlockData(
"*Paper_Space0", 0, 0.0, 0.0, 0.0));
238 dxf.writeEndBlock(*dw,
"*Paper_Space0");
245 dw->sectionEntities();
252 }
else if (ySpan == 0) {
267 unsigned vertexCount =
profile->size();
270 DL_PolylineData(
static_cast<int>(vertexCount), 0, 0, 0),
274 for (
unsigned i = 0; i < vertexCount; ++i) {
276 dxf.writeVertex(*dw, DL_VertexData(x0 + (P->
x - xMin) * scale,
277 y0 + (P->
y + heightShift -
282 dxf.writePolylineEnd(*dw);
287 DL_Attributes DefaultLegendMaterial(
LEGEND_LAYER, DL_Codes::bylayer,
292 dxf.writePolyline(*dw, DL_PolylineData(4, 0, 0, 1),
293 DefaultLegendMaterial);
309 dxf.writePolylineEnd(*dw);
314 const double legendWidth_mm = 20.0;
317 QString magnifyStr = QString::number(
params.devMagnifyCoef);
320 DL_TextData(xLegend, yLegend, 0.0, xLegend, yLegend, 0.0,
322 qPrintable(QString(
"Deviation magnification "
328 DefaultLegendMaterial);
335 DL_TextData(xLegend, yLegend, 0.0, xLegend, yLegend,
337 qPrintable(QString(
"Deviation units: ") +
340 DefaultLegendMaterial);
347 DL_LineData(xLegend, yLegend, 0,
348 xLegend + legendWidth_mm, yLegend, 0.0),
358 qPrintable(
params.legendRealProfileTitle),
362 DefaultLegendMaterial);
369 DL_LineData(xLegend, yLegend, 0,
370 xLegend + legendWidth_mm, yLegend, 0.0),
380 qPrintable(
params.legendTheoProfileTitle),
384 DefaultLegendMaterial);
388 for (
unsigned angleStep = 0; angleStep < angularStepCount;
390 std::vector<VertStepData> polySteps;
392 polySteps.reserve(map->ySteps);
393 }
catch (
const std::bad_alloc&) {
401 unsigned iMap =
static_cast<unsigned>(
402 static_cast<double>(angleStep * map->xSteps) /
403 static_cast<double>(angularStepCount));
404 for (
unsigned jMap = 0; jMap < map->ySteps; ++jMap) {
406 map->at(iMap + jMap * map->xSteps);
410 map->yMin +
static_cast<double>(jMap) * map->yStep;
415 for (
unsigned i = 1; i <
profile->size(); ++i) {
419 double alpha =
static_cast<double>(
420 (step.
height - A->
y - heightShift) /
422 if (alpha >= 0.0 && alpha <= 1.0) {
433 polySteps.push_back(step);
438 const DL_Attributes DefaultMaterial(
439 qPrintable(profileNames[angleStep]), DL_Codes::bylayer, -1,
442 const DL_Attributes GrayMaterial(
443 qPrintable(profileNames[angleStep]), DL_Codes::l_gray, -1,
447 if (
static_cast<int>(angleStep) <
params.profileTitles.size()) {
448 const QString& title =
params.profileTitles[angleStep];
456 DL_TextData(Ptop.
x, Ptop.
y, Ptop.
z, Ptop.
x, Ptop.
y,
458 qPrintable(title),
"STANDARD",
468 DL_PolylineData(
static_cast<int>(polySteps.size()), 0,
472 for (
size_t i = 0; i < polySteps.size(); ++i) {
480 y0 + (step.
height - yMin) * scale,
484 dxf.writePolylineEnd(*dw);
488 CCVector3d pageShift(x0 - xMin * scale, y0 - yMin * scale, 0.0);
491 for (
size_t i = 0; i < polySteps.size(); ++i) {
493 bool displayIt = (i == 0 || i + 1 == polySteps.size());
495 double dh = polySteps[i].
height -
496 polySteps[lastStep].height;
497 double next_dh = polySteps[i + 1].height -
498 polySteps[lastStep].height;
499 if (dh >= heightStep ||
500 (next_dh > heightStep &&
501 fabs(dh - heightStep) <
502 fabs(next_dh - heightStep))) {
515 Pheight = pageShift + Pheight * scale;
516 Pdev = pageShift + Pdev * scale;
521 DL_LineData(Pheight.
x, Pheight.
y, Pheight.
z,
522 Pdev.
x, Pdev.
y, Pdev.
z),
529 int hJustification = 0;
532 int vJustification = 2;
549 QString::number(polySteps[i].deviation *
554 DL_TextData(Pdev.
x, Pdev.
y, Pdev.
z, Pdev.
x,
556 1.0, 0, hJustification,
557 vJustification, qPrintable(devText),
564 QString heightText = QString::number(
568 DL_TextData(Pheight.
x, Pheight.
y, Pheight.
z,
569 Pheight.
x, Pheight.
y, Pheight.
z,
571 2 - hJustification, vJustification,
572 qPrintable(heightText),
"STANDARD",
586 dxf.writeObjects(*dw);
587 dxf.writeObjectsEnd(*dw);
608 const QSharedPointer<DistanceMapGenerationTool::Map>& map,
611 unsigned heightStepCount,
613 double angularStep_rad,
614 double radToUnitConvFactor,
618 #ifdef CV_DXF_SUPPORT
623 if (!map || !
profile || heightStepCount == 0 || angularStep_rad <= 0) {
630 profile->getAssociatedCloud()->getBoundingBox(profileBBMin, profileBBMax);
633 map->yMin + 0.5 * map->xStep,
634 static_cast<double>(profileBBMin.
y) + heightShift);
636 map->yMin + (
static_cast<double>(map->ySteps) - 0.5) *
638 static_cast<double>(profileBBMax.
y) + heightShift);
639 const double ySpan = yMax - yMin;
643 const double xMax = profileBBMax.
x;
645 const double& maxRadius = xMax;
649 app->
dispToConsole(QString(
"Internal error: null profile?!"),
655 DL_WriterA* dw = dxf.out(qPrintable(
filename), DL_VERSION_R12);
658 app->
dispToConsole(QString(
"Failed to open '%1' file for writing!")
665 dxf.writeHeader(*dw);
668 dw->dxfString(9,
"$INSBASE");
669 dw->dxfReal(10, 0.0);
670 dw->dxfReal(20, 0.0);
671 dw->dxfReal(30, 0.0);
672 dw->dxfString(9,
"$EXTMIN");
673 dw->dxfReal(10, 0.0);
674 dw->dxfReal(20, 0.0);
675 dw->dxfReal(30, 0.0);
676 dw->dxfString(9,
"$EXTMAX");
679 dw->dxfReal(30, 0.0);
680 dw->dxfString(9,
"$LIMMIN");
681 dw->dxfReal(10, 0.0);
682 dw->dxfReal(20, 0.0);
683 dw->dxfString(9,
"$LIMMAX");
697 dw->tableLinetypes(3);
698 dxf.writeLinetype(*dw,
699 DL_LinetypeData(
"BYBLOCK",
"BYBLOCK", 0, 0, 0.0));
700 dxf.writeLinetype(*dw,
701 DL_LinetypeData(
"BYLAYER",
"BYLAYER", 0, 0, 0.0));
703 *dw, DL_LinetypeData(
"CONTINUOUS",
"Continuous", 0, 0, 0.0));
708 dw->tableLayers(heightStepCount + 2);
709 QStringList profileNames;
712 dxf.writeLayer(*dw, DL_LayerData(
"0", 0),
713 DL_Attributes(std::string(
""),
726 for (
unsigned i = 0; i < heightStepCount; ++i) {
741 profileNames << layerName;
744 DL_LayerData(qPrintable(layerName),
747 DL_Attributes(std::string(
""),
759 dxf.writeStyle(*dw, DL_StyleData(
"Standard", 0, 0.0, 0.75, 0.0, 0, 2.5,
767 dw->tableAppidEntry(0x12);
768 dw->dxfString(2,
"ACAD");
773 dxf.writeDimStyle(*dw,
781 dxf.writeBlockRecord(*dw);
791 dxf.writeBlock(*dw, DL_BlockData(
"*Model_Space", 0, 0.0, 0.0, 0.0));
792 dxf.writeEndBlock(*dw,
"*Model_Space");
794 dxf.writeBlock(*dw, DL_BlockData(
"*Paper_Space", 0, 0.0, 0.0, 0.0));
795 dxf.writeEndBlock(*dw,
"*Paper_Space");
797 dxf.writeBlock(*dw, DL_BlockData(
"*Paper_Space0", 0, 0.0, 0.0, 0.0));
798 dxf.writeEndBlock(*dw,
"*Paper_Space0");
805 dw->sectionEntities();
822 DL_Attributes DefaultLegendMaterial(
LEGEND_LAYER, DL_Codes::bylayer,
827 dxf.writePolyline(*dw, DL_PolylineData(4, 0, 0, 1),
828 DefaultLegendMaterial);
844 dxf.writePolylineEnd(*dw);
849 const double legendWidth_mm = 20.0;
852 double axisTip = maxRadius * scale + 5.0;
853 dxf.writeLine(*dw, DL_LineData(xc, yc, 0.0, xc, yc - axisTip, 0.0),
854 DefaultLegendMaterial);
858 double axisTipSize = 3.0;
861 *dw, DL_PolylineData(3, 0, 0, 1),
862 DefaultLegendMaterial);
865 DL_VertexData(xc, yc - (axisTip + axisTipSize), 0.0));
866 dxf.writeVertex(*dw, DL_VertexData(xc - axisTipSize / 2.0,
868 dxf.writeVertex(*dw, DL_VertexData(xc + axisTipSize / 2.0,
870 dxf.writePolylineEnd(*dw);
874 DL_TextData(xc, yc - (axisTip + 2.0 * axisTipSize), 0.0,
875 xc, yc - (axisTip + 2.0 * axisTipSize), 0.0,
878 DefaultLegendMaterial);
882 QString magnifyStr = QString::number(
params.devMagnifyCoef);
885 DL_TextData(xLegend, yLegend, 0.0, xLegend, yLegend, 0.0,
887 qPrintable(QString(
"Deviation magnification "
893 DefaultLegendMaterial);
901 DL_TextData(xLegend, yLegend, 0.0, xLegend, yLegend, 0.0,
903 qPrintable(QString(
"Deviation units: ") +
908 DefaultLegendMaterial);
915 DL_LineData(xLegend, yLegend, 0,
916 xLegend + legendWidth_mm, yLegend, 0.0),
926 qPrintable(
params.legendRealProfileTitle),
928 DefaultLegendMaterial);
935 DL_LineData(xLegend, yLegend, 0,
936 xLegend + legendWidth_mm, yLegend, 0.0),
946 qPrintable(
params.legendTheoProfileTitle),
948 DefaultLegendMaterial);
952 std::vector<HorizStepData> polySteps;
954 polySteps.resize(map->xSteps);
955 }
catch (
const std::bad_alloc&) {
964 for (
unsigned heightStep = 0; heightStep < heightStepCount;
968 yMin +
static_cast<double>(heightStep) /
969 static_cast<double>(heightStepCount - 1) *
973 if (height < map->yMin ||
974 height >= map->yMin +
static_cast<double>(map->ySteps) *
982 static_cast<unsigned>((
height - map->yMin) / map->yStep);
983 assert(jMap < map->ySteps);
986 double currentRadius = 0.0;
989 for (
unsigned i = 1; i <
profile->size(); ++i) {
993 double alpha =
static_cast<double>(
994 (
height - A->
y - heightShift) / (B->
y - A->
y));
995 if (alpha >= 0.0 && alpha <= 1.0) {
997 currentRadius = A->
x + alpha * (B->
x - A->
x);
1011 const QString& currentLayer = profileNames[heightStep];
1012 const DL_Attributes DefaultMaterial(
1013 qPrintable(currentLayer), DL_Codes::bylayer, -1,
"BYLAYER",
1016 const DL_Attributes GrayMaterial(qPrintable(currentLayer),
1017 DL_Codes::l_gray, -1,
"", 1.0);
1020 if (
params.profileTitles.size() == 1) {
1021 QString title = QString(
params.profileTitles[0])
1031 DL_TextData(Ptop.
x, Ptop.
y, Ptop.
z, Ptop.
x, Ptop.
y,
1033 qPrintable(title),
"STANDARD",
1042 *dw, DL_CircleData(xc, yc, 0.0, currentRadius * scale),
1044 -1,
"BYLAYER", 1.0));
1047 assert(polySteps.size() == map->xSteps);
1050 &map->at(jMap * map->xSteps);
1051 for (
unsigned iMap = 0; iMap < map->xSteps; ++iMap, ++cell) {
1054 static_cast<double>(map->xSteps);
1056 polySteps[iMap] = step;
1061 double cwSign = map->counterclockwise ? -1.0 : 1.0;
1069 DL_PolylineData(
static_cast<int>(polySteps.size()), 0,
1073 for (
size_t i = 0; i < polySteps.size(); ++i) {
1075 double radius = currentRadius +
1079 DL_VertexData(pageShift.
x - (cwSign * radius *
1082 pageShift.
y - (radius *
1088 dxf.writePolylineEnd(*dw);
1093 size_t lastStep = 0;
1094 for (
size_t i = 0; i < polySteps.size(); ++i) {
1101 double dAngle = polySteps[i].
angle_rad -
1102 polySteps[lastStep].angle_rad;
1103 double next_dAngle =
1104 (i + 1 == polySteps.size()
1105 ? polySteps[0].angle_rad + 2.0 *
M_PI
1106 : polySteps[i + 1].angle_rad) -
1107 polySteps[lastStep].angle_rad;
1108 if (dAngle >= angularStep_rad ||
1109 (next_dAngle > angularStep_rad &&
1110 fabs(dAngle - angularStep_rad) <
1111 fabs(next_dAngle - angularStep_rad))) {
1116 if (displayIt && i != 0)
1121 CCVector3d Pangle = relativePos * currentRadius;
1128 Pangle = pageShift + Pangle * scale;
1129 Pdev = pageShift + Pdev * scale;
1133 DL_LineData(Pangle.
x, Pangle.
y, Pangle.
z,
1134 Pdev.
x, Pdev.
y, Pdev.
z),
1140 const double c_angleMargin_rad =
1142 const double c_margin = sin(c_angleMargin_rad);
1146 int hJustification = 1;
1147 if (relativePos.
x < -c_margin)
1149 else if (relativePos.
x > c_margin)
1155 int vJustification = 2;
1159 else if (relativePos.
y >
1163 int hJustificationDev = hJustification;
1164 int hJustificationAng = hJustification;
1165 int vJustificationDev = vJustification;
1166 int vJustificationAng = vJustification;
1175 if (hJustificationDev != 1)
1177 2 - hJustificationDev;
1178 if (vJustificationDev != 2)
1180 4 - vJustificationDev;
1185 if (hJustificationAng != 1)
1187 2 - hJustificationAng;
1188 if (vJustificationAng != 2)
1190 4 - vJustificationAng;
1194 QString::number(polySteps[i].deviation *
1200 Pdev.
x, Pdev.
y, Pdev.
z, Pdev.
x, Pdev.
y,
1202 hJustificationDev, vJustificationDev,
1203 qPrintable(devText),
"STANDARD", 0.0),
1207 QString::number(polySteps[i].angle_rad *
1208 radToUnitConvFactor,
1212 DL_TextData(Pangle.
x, Pangle.
y, Pangle.
z,
1213 Pangle.
x, Pangle.
y, Pangle.
z,
1217 qPrintable(angleText),
1231 dxf.writeObjects(*dw);
1232 dxf.writeObjectsEnd(*dw);
CloudViewerScene::LightingProfile profile
cmdLineReadable * params[]
static bool SaveHorizontalProfiles(const QSharedPointer< DistanceMapGenerationTool::Map > &map, ccPolyline *profile, QString filename, unsigned heightStepCount, double heightShift, double angularStep_rad, double radToUnitConvFactor, QString angleUnit, const Parameters ¶ms, ecvMainAppInterface *app=0)
static bool SaveVerticalProfiles(const QSharedPointer< DistanceMapGenerationTool::Map > &map, ccPolyline *profile, QString filename, unsigned angularStepCount, double heightStep, double heightShift, const Parameters ¶ms, ecvMainAppInterface *app=0)
static bool IsEnabled()
Returns whether DXF support is enabled or not.
Main application interface (for plugins)
virtual void dispToConsole(QString message, ConsoleMessageLevel level=STD_CONSOLE_MESSAGE)=0
__host__ __device__ float2 fabs(float2 v)
static const double c_textHeight_mm
static const double c_textMargin_mm
static const double c_profileMargin_mm
static const char HORIZ_PROFILE_LAYER[]
static const char LEGEND_LAYER[]
static const double c_pageHeight_mm
static const double c_pageWidth_mm
static const double c_pageMargin_mm
static const char PROFILE_LAYER[]
static const char VERT_PROFILE_LAYER[]
static const int s_lineWidth
constexpr Rgb black(0, 0, 0)
constexpr Rgb red(MAX, 0, 0)
constexpr Rgb green(0, MAX, 0)