32 #include <vtkAnnotatedCubeActor.h>
33 #include <vtkAppendPolyData.h>
34 #include <vtkAxesActor.h>
35 #include <vtkCaptionActor2D.h>
36 #include <vtkCellData.h>
37 #include <vtkDataSet.h>
38 #include <vtkDataSetMapper.h>
39 #include <vtkLODActor.h>
41 #include <vtkLineSource.h>
42 #include <vtkPlaneSource.h>
43 #include <vtkPointData.h>
44 #include <vtkPoints.h>
45 #include <vtkPolygon.h>
46 #include <vtkPropAssembly.h>
47 #include <vtkProperty.h>
48 #include <vtkProperty2D.h>
49 #include <vtkSmartPointer.h>
50 #include <vtkTextActor.h>
51 #include <vtkTextProperty.h>
52 #include <vtkTexture.h>
53 #include <vtkUnsignedCharArray.h>
54 #include <vtkUnstructuredGrid.h>
56 #if VTK_RENDERING_BACKEND_OPENGL_VERSION < 2
57 #include <pcl/visualization/vtk/vtkVertexBufferObjectMapper.h>
67 #include <pcl/common/transforms.h>
68 #include <pcl/features/normal_3d.h>
69 #include <pcl/io/vtk_lib_io.h>
70 #include <pcl/visualization/pcl_visualizer.h>
89 #if VTK_RENDERING_BACKEND_OPENGL_VERSION < 2
94 mapper->SetInput(
data);
98 data->GetPointData()->GetScalars();
101 scalars->GetRange(minmax);
102 mapper->SetScalarRange(minmax);
104 mapper->SetScalarModeToUsePointData();
105 mapper->SetInterpolateScalarsBeforeMapping(
107 mapper->ScalarVisibilityOn();
111 actor->SetNumberOfCloudPoints(
112 int(std::max<vtkIdType>(1,
data->GetNumberOfPoints() / 10)));
113 actor->GetProperty()->SetInterpolationToFlat();
121 actor->SetMapper(mapper);
127 #if VTK_MAJOR_VERSION < 6
128 mapper->SetInput(
data);
130 mapper->SetInputData(
data);
135 data->GetPointData()->GetScalars();
138 scalars->GetRange(minmax);
139 mapper->SetScalarRange(minmax);
141 mapper->SetScalarModeToUsePointData();
142 mapper->SetInterpolateScalarsBeforeMapping(
144 mapper->ScalarVisibilityOn();
147 #if VTK_RENDERING_BACKEND_OPENGL_VERSION < 2
148 mapper->ImmediateModeRenderingOff();
151 actor->SetNumberOfCloudPoints(
152 int(std::max<vtkIdType>(1,
data->GetNumberOfPoints() / 10)));
153 actor->GetProperty()->SetInterpolationToFlat();
161 actor->SetMapper(mapper);
174 #if VTK_RENDERING_BACKEND_OPENGL_VERSION < 2
179 mapper->SetInput(
data);
183 data->GetPointData()->GetScalars();
186 scalars->GetRange(minmax);
187 mapper->SetScalarRange(minmax);
189 mapper->SetScalarModeToUsePointData();
190 mapper->SetInterpolateScalarsBeforeMapping(
192 mapper->ScalarVisibilityOn();
198 actor->GetProperty()->SetInterpolationToFlat();
206 actor->SetMapper(mapper);
212 #if VTK_MAJOR_VERSION < 6
213 mapper->SetInput(
data);
215 mapper->SetInputData(
data);
220 data->GetPointData()->GetScalars();
223 scalars->GetRange(minmax);
224 mapper->SetScalarRange(minmax);
226 mapper->SetScalarModeToUsePointData();
227 mapper->SetInterpolateScalarsBeforeMapping(
229 mapper->ScalarVisibilityOn();
232 #if VTK_RENDERING_BACKEND_OPENGL_VERSION < 2
233 mapper->ImmediateModeRenderingOff();
238 actor->GetProperty()->SetInterpolationToFlat();
246 actor->SetMapper(mapper);
251 actor->GetProperty()->SetInterpolationToFlat();
263 linePoints->SetNumberOfPoints(
264 static_cast<vtkIdType
>(2 * lineset.
lines_.size()));
265 for (std::size_t i = 0; i < lineset.
lines_.size(); ++i) {
266 std::pair<Eigen::Vector3d, Eigen::Vector3d> segment =
268 linePoints->SetPoint(
static_cast<vtkIdType
>(2 * i),
269 segment.first.data());
270 linePoints->SetPoint(
static_cast<vtkIdType
>(2 * i + 1),
271 segment.second.data());
285 bool has_color =
false;
288 colors->SetNumberOfComponents(3);
289 colors->SetName(
"Colors");
290 colors->SetNumberOfTuples(
291 static_cast<vtkIdType
>(lineset.
points_.size()));
294 points->SetNumberOfPoints(
static_cast<vtkIdType
>(lineset.
points_.size()));
295 for (std::size_t i = 0; i < lineset.
points_.size(); ++i) {
296 Eigen::Vector3d p = lineset.
points_[i];
297 points->SetPoint(
static_cast<vtkIdType
>(i), p.data());
300 for (std::size_t i = 0; i < lineset.
lines_.size(); ++i) {
303 segment->GetPointIds()->SetId(0, segIndex(0));
304 segment->GetPointIds()->SetId(1, segIndex(1));
305 lines->InsertNextCell(segment);
320 lineSource->SetPoints(
points);
321 lineSource->Update();
322 return lineSource->GetOutput();
329 if (
points->GetNumberOfPoints() == 0 && lines->GetNumberOfCells() == 0 &&
330 colors->GetNumberOfTuples() == 0) {
335 if (
points->GetNumberOfPoints() > 0) {
336 polyData->SetPoints(
points);
338 if (lines->GetNumberOfCells() > 0) {
339 polyData->SetLines(lines);
341 if (
colors->GetNumberOfTuples() > 0) {
342 polyData->GetCellData()->SetScalars(
colors);
352 colors->SetNumberOfComponents(3);
353 colors->SetName(
"Colors");
356 colors->SetNumberOfTuples(polyData->GetPolys()->GetNumberOfCells());
357 for (vtkIdType i = 0; i < polyData->GetPolys()->GetNumberOfCells();
361 polyData->GetCellData()->SetScalars(
colors);
363 colors->SetNumberOfTuples(polyData->GetNumberOfPoints());
364 for (vtkIdType i = 0; i < polyData->GetNumberOfPoints(); ++i) {
367 polyData->GetPointData()->SetScalars(
colors);
374 vtkIdType n_points = polyData->GetNumberOfPoints();
376 vtkIdType cellId1[3] = {0, 1, 3};
377 cellArray->InsertNextCell(3, cellId1);
378 vtkIdType cellId2[3] = {7, 6, 4};
379 cellArray->InsertNextCell(3, cellId2);
380 polyData->SetPolys(cellArray);
381 }
else if (n_points == 14) {
382 vtkIdType cellId1[3] = {0, 1, 3};
383 cellArray->InsertNextCell(3, cellId1);
384 vtkIdType cellId2[3] = {7, 6, 4};
385 cellArray->InsertNextCell(3, cellId2);
387 vtkIdType cellId3[3] = {8, 9, 11};
388 cellArray->InsertNextCell(3, cellId3);
389 polyData->SetPolys(cellArray);
395 assert(lineset.
lines_.size() == 3);
399 lineR->SetNumberOfPoints(2);
400 std::pair<Eigen::Vector3d, Eigen::Vector3d> segmentR =
402 lineR->SetPoint(
static_cast<vtkIdType
>(0), segmentR.first.data());
403 lineR->SetPoint(
static_cast<vtkIdType
>(1), segmentR.second.data());
409 lineUp->SetNumberOfPoints(2);
410 std::pair<Eigen::Vector3d, Eigen::Vector3d> segmentUp =
412 lineUp->SetPoint(
static_cast<vtkIdType
>(0), segmentUp.first.data());
413 lineUp->SetPoint(
static_cast<vtkIdType
>(1), segmentUp.second.data());
419 lineV->SetNumberOfPoints(2);
420 std::pair<Eigen::Vector3d, Eigen::Vector3d> segmentV =
422 lineV->SetPoint(
static_cast<vtkIdType
>(0), segmentV.first.data());
423 lineV->SetPoint(
static_cast<vtkIdType
>(1), segmentV.second.data());
429 appendFilter->AddInputData(rLinesData);
430 appendFilter->AddInputData(uLinesData);
431 appendFilter->AddInputData(vLinesData);
432 appendFilter->Update();
433 return appendFilter->GetOutput();
457 appendFilter->AddInputData(headLinesData);
458 appendFilter->AddInputData(legLinesData);
459 appendFilter->AddInputData(axisLinesData);
460 appendFilter->Update();
461 return appendFilter->GetOutput();
468 assert(cameraSensor);
493 appendFilter->AddInputData(nearPlaneLinesData);
494 appendFilter->AddInputData(sideLinesData);
495 appendFilter->AddInputData(arrowLinesData);
496 appendFilter->AddInputData(axisLinesData);
497 appendFilter->Update();
498 return appendFilter->GetOutput();
502 const pcl::ModelCoefficients& coefficients) {
505 plane->SetNormal(coefficients.values[0], coefficients.values[1],
506 coefficients.values[2]);
508 double norm_sqr = coefficients.values[0] * coefficients.values[0] +
509 coefficients.values[1] * coefficients.values[1] +
510 coefficients.values[2] * coefficients.values[2];
512 plane->Push(-coefficients.values[3] / sqrt(norm_sqr));
514 return (plane->GetOutput());
518 const pcl::ModelCoefficients& coefficients,
526 double norm_sqr = 1.0 / (coefficients.values[0] * coefficients.values[0] +
527 coefficients.values[1] * coefficients.values[1] +
528 coefficients.values[2] * coefficients.values[2]);
530 plane->SetNormal(coefficients.values[0], coefficients.values[1],
531 coefficients.values[2]);
532 double t =
x * coefficients.values[0] +
y * coefficients.values[1] +
533 z * coefficients.values[2] + coefficients.values[3];
534 x -= coefficients.values[0] * t * norm_sqr;
535 y -= coefficients.values[1] * t * norm_sqr;
536 z -= coefficients.values[2] * t * norm_sqr;
538 plane->SetCenter(
x,
y,
z);
541 Eigen::Vector3d p1, p2;
543 n.x() =
x + coefficients.values[0];
544 n.y() =
y + coefficients.values[1];
545 n.z() =
z + coefficients.values[2];
549 p1.z() = (coefficients.values[3] - coefficients.values[0] * p1.x() -
550 coefficients.values[1] * p1.y()) /
551 coefficients.values[2];
572 plane->SetOrigin(
x,
y,
z);
573 plane->SetPoint1(point1);
574 plane->SetPoint2(point2);
578 return plane->GetOutput();
583 const std::string& xLabel,
584 const std::string& yLabel,
585 const std::string& zLabel,
586 const std::string& xPlus,
587 const std::string& xMinus,
588 const std::string& yPlus,
589 const std::string& yMinus,
590 const std::string& zPlus,
591 const std::string& zMinus) {
593 axes->SetShaftTypeToCylinder();
594 axes->SetXAxisLabelText(xLabel.c_str());
595 axes->SetYAxisLabelText(yLabel.c_str());
596 axes->SetZAxisLabelText(zLabel.c_str());
597 axes->GetXAxisTipProperty()->SetColor(1.0, 0.0, 0.0);
598 axes->GetXAxisShaftProperty()->SetColor(1.0, 0.0, 0.0);
599 axes->GetYAxisTipProperty()->SetColor(1.0, 1.0, 0.0);
600 axes->GetYAxisShaftProperty()->SetColor(1.0, 1.0, 0.0);
601 axes->GetZAxisTipProperty()->SetColor(0.0, 1.0, 0.0);
602 axes->GetZAxisShaftProperty()->SetColor(0.0, 1.0, 0.0);
603 axes->SetTotalLength(axesLength, axesLength, axesLength);
607 cube->SetXPlusFaceText(xPlus.c_str());
608 cube->SetXMinusFaceText(xMinus.c_str());
609 cube->SetYPlusFaceText(yPlus.c_str());
610 cube->SetYMinusFaceText(yMinus.c_str());
611 cube->SetZPlusFaceText(zPlus.c_str());
612 cube->SetZMinusFaceText(zMinus.c_str());
613 cube->SetXFaceTextRotation(180);
614 cube->SetYFaceTextRotation(180);
615 cube->SetZFaceTextRotation(-90);
616 cube->SetFaceTextScale(0.65);
617 cube->GetCubeProperty()->SetColor(0.5, 1, 1);
618 cube->GetTextEdgesProperty()->SetLineWidth(1);
619 cube->GetTextEdgesProperty()->SetDiffuse(0);
620 cube->GetTextEdgesProperty()->SetAmbient(1);
621 cube->GetTextEdgesProperty()->SetColor(0.1800, 0.2800, 0.2300);
624 vtkMapper::SetResolveCoincidentTopologyToPolygonOffset();
626 cube->GetXPlusFaceProperty()->SetColor(1.0, 0.0, 0.0);
627 cube->GetXPlusFaceProperty()->SetInterpolationToFlat();
628 cube->GetXMinusFaceProperty()->SetColor(1.0, 0.0, 0.0);
629 cube->GetXMinusFaceProperty()->SetInterpolationToFlat();
630 cube->GetYPlusFaceProperty()->SetColor(1.0, 1.0, 0.0);
631 cube->GetYPlusFaceProperty()->SetInterpolationToFlat();
632 cube->GetYMinusFaceProperty()->SetColor(1.0, 1.0, 0.0);
633 cube->GetYMinusFaceProperty()->SetInterpolationToFlat();
634 cube->GetZPlusFaceProperty()->SetColor(0.0, 1.0, 0.0);
635 cube->GetZPlusFaceProperty()->SetInterpolationToFlat();
636 cube->GetZMinusFaceProperty()->SetColor(0.0, 1.0, 0.0);
637 cube->GetZMinusFaceProperty()->SetInterpolationToFlat();
642 tprop4->SetFontFamilyToArial();
645 axes->GetXAxisCaptionActor2D()->SetCaptionTextProperty(tprop4);
649 tprop2->ShallowCopy(tprop4);
650 axes->GetYAxisCaptionActor2D()->SetCaptionTextProperty(tprop2);
654 tprop3->ShallowCopy(tprop4);
655 axes->GetZAxisCaptionActor2D()->SetCaptionTextProperty(tprop3);
659 assembly->AddPart(cube);
660 assembly->AddPart(axes);
676 : yPos(
y), yMin(y1), yMax(y2), val(v) {
686 ScalarType absDispMin = (dispMax < 0 ? std::min(-dispMax, -dispMin)
687 : std::max<ScalarType>(dispMin, 0));
688 ScalarType absDispMax = std::max(std::abs(dispMin), std::abs(dispMax));
689 dispMin = std::log10(
690 std::max(absDispMin, std::numeric_limits<ScalarType>::epsilon()));
691 dispMax = std::log10(
692 std::max(absDispMax, std::numeric_limits<ScalarType>::epsilon()));
698 using vlabelPair = std::pair<vlabelSet::iterator, vlabelSet::iterator>;
704 vlabelSet::iterator it1 = set.begin();
708 vlabelSet::iterator it2 = it1;
710 for (; it2 != set.end(); ++it2, ++it1) {
721 if (!widget)
return false;
735 bool customLabels =
false;
738 if (colorScale && colorScale->customLabels().size() >= 2) {
739 keyValues = colorScale->customLabels();
741 if (alwaysShowZero) {
742 keyValues.insert(0.0);
746 }
else if (!logScale) {
756 if (symmetricalScale)
759 if (alwaysShowZero) keyValues.insert(0.0);
764 keyValues.insert(minDisp);
765 keyValues.insert(maxDisp);
770 keyValues.insert(startDisp);
771 keyValues.insert(stopDisp);
778 }
catch (
const std::bad_alloc&) {
785 for (ccColorScale::LabelSet::iterator it = keyValues.begin();
786 it != keyValues.end(); ++it) {
787 #if defined(CV_WINDOWS) && defined(_MSC_VER)
788 if (!_finite(it->value))
790 if (!std::isfinite(it->value))
793 bool minusInf = (it->value < 0);
796 keyValues.insert({std::numeric_limits<ScalarType>::lowest(),
800 {std::numeric_limits<ScalarType>::max(),
"+Inf"});
801 it = keyValues.begin();
813 for (ccColorScale::LabelSet::iterator it = keyValues.begin();
814 it != keyValues.end();) {
816 static_cast<ScalarType
>(it->value)) &&
821 ccColorScale::LabelSet::iterator toDelete = it;
823 keyValues.erase(toDelete);
836 for (ccColorScale::LabelSet::iterator it = keyValues.begin();
837 it != keyValues.end();) {
838 if (it->value >= dispMin && it->value <= dispMax) {
841 ccColorScale::LabelSet::iterator toDelete = it;
843 keyValues.erase(toDelete);
849 std::vector<ccColorScale::Label> sortedKeyValues(keyValues.begin(),
852 sortedKeyValues.back().value - sortedKeyValues.front().value;
861 histogram.
maxValue != 0 && histogram.size() > 1);
867 const int strHeight =
871 const int scaleWidth =
873 const int scaleMaxHeight =
874 (keyValues.size() > 1
876 CONTEXT.
glH -
static_cast<int>(140 * renderZoom),
884 drawnLabels.emplace_back(0, 0, strHeight,
885 sortedKeyValues.front().value);
887 if (keyValues.size() > 1) {
889 drawnLabels.emplace_back(scaleMaxHeight, scaleMaxHeight - strHeight,
891 sortedKeyValues.back().value);
895 if (keyValues.size() > 2) {
896 assert(maxRange > 0.0);
897 const int minGap = strHeight;
898 for (
size_t i = 1; i < keyValues.size() - 1; ++i) {
899 int yScale =
static_cast<int>(
900 (sortedKeyValues[i].value - sortedKeyValues[0].value) *
901 scaleMaxHeight / maxRange);
904 assert(nLabels.first != drawnLabels.end() &&
905 nLabels.second != drawnLabels.end());
906 if ((nLabels.first == drawnLabels.end() ||
907 nLabels.first->yMax <= yScale - minGap) &&
908 (nLabels.second == drawnLabels.end() ||
909 nLabels.second->yMin >= yScale + minGap)) {
912 drawnLabels.insert(nLabels.second,
913 vlabel(yScale, yScale - strHeight / 2,
914 yScale + strHeight / 2,
915 sortedKeyValues[i].value));
921 if (!customLabels && drawnLabels.size() > 1) {
922 const int minGap = strHeight * 2;
924 size_t drawnLabelsBefore = 0;
925 size_t drawnLabelsAfter = drawnLabels.size();
928 while (drawnLabelsAfter > drawnLabelsBefore) {
929 drawnLabelsBefore = drawnLabelsAfter;
931 vlabelSet::iterator it1 = drawnLabels.begin();
932 vlabelSet::iterator it2 = it1;
934 for (; it2 != drawnLabels.end(); ++it2) {
935 if (it1->yMax + 2 * minGap < it2->yMin) {
937 double val = (it1->val + it2->val) / 2.0;
938 int yScale =
static_cast<int>(
939 (val - sortedKeyValues[0].value) *
940 scaleMaxHeight / maxRange);
945 it2,
vlabel(yScale, yScale - strHeight / 2,
946 yScale + strHeight / 2, val));
951 drawnLabelsAfter = drawnLabels.size();
958 vtkScalarBarWidgetCustom::SafeDownCast(widget);
959 if (!scalarBarWidget) {
963 vtkContext2DScalarBarActor::SafeDownCast(
966 scalarBarWidget->Off();
971 vtkScalarBarRepresentationCustom::SafeDownCast(
972 scalarBarWidget->GetRepresentation());
974 rep->SetWindowLocation(
998 for (
int j = 0; j < scaleMaxHeight; ++j) {
999 double baseValue = sortedKeyValues.front().value +
1000 (j * maxRange) / scaleMaxHeight;
1001 double value = baseValue;
1003 value = std::exp(value *
c_log10);
1006 sf->
getColor(
static_cast<ScalarType
>(value));
1022 lut->AddRGBPoint(value,
rgb(0),
rgb(1),
rgb(2));
1027 const char* sfName = sf->
getName();
1028 QString sfTitle(sfName);
1031 if (logScale) sfTitle += QString(
"[Log scale]");
1034 lutActor->SetLookupTable(lut);
1035 lutActor->SetOutlineScalarBar(showHistogram);
1036 lutActor->SetScalarBarLength(0.8);
1037 lutActor->SetScalarBarThickness(scaleWidth);
1038 lutActor->SetTitleJustification(VTK_TEXT_CENTERED);
1039 lutActor->SetForceHorizontalTitle(
true);
1040 lutActor->SetDrawColorBar(1);
1041 lutActor->SetDrawTickLabels(1);
1043 lutActor->SetNumberOfTicks(
static_cast<int>(drawnLabels.size()));
1047 lutActor->SetTextPositionToPrecedeScalarBar();
1049 lutActor->GetLabelTextProperty()->SetFontSize(
1051 lutActor->SetDrawFrame(1);
1053 lutActor->GetFrameProperty()->SetColor(col(0), col(1), col(2));
1054 lutActor->GetAnnotationTextProperty()->SetColor(col(0), col(1), col(2));
1055 lutActor->GetTitleTextProperty()->SetColor(col(0), col(1), col(2));
1056 lutActor->GetLabelTextProperty()->SetColor(col(0), col(1), col(2));
1057 lutActor->GetFrameProperty()->SetLineWidth(2.0f * renderZoom);
1064 QString formatInfo =
1065 QString(
"%1.%2%3").arg(precision).arg(precision).arg(
format);
1066 const std::string labelFormat =
"%" + formatInfo.toStdString();
1067 lutActor->SetRangeLabelFormat(labelFormat.c_str());
1069 scalarBarWidget->On();
1070 scalarBarWidget->Modified();
1093 for (vtkIdType i = 0; i <
points->GetNumberOfPoints(); ++i) {
1094 double* P =
points->GetPoint(i);
1107 CVLog::Error(
"[PclTools::CreateCube] Creating cube failed!");
1117 cube->SetXLength(
width);
1118 cube->SetYLength(
height);
1119 cube->SetZLength(depth);
1121 return cube->GetOutput();
1126 bool useLineSource ) {
1127 if (useLineSource) {
1144 using namespace pcl;
1148 void showCameras(pcl::texture_mapping::CameraVector cams,
1149 pcl::PointCloud<PointT>::Ptr& cloud) {
1151 pcl::visualization::PCLVisualizer visu(
"cameras");
1154 for (std::size_t i = 0; i < cams.size(); ++i) {
1156 pcl::TextureMapping<PointT>::Camera cam = cams[i];
1157 double focal = cam.focal_length;
1158 double height = cam.height;
1159 double width = cam.width;
1162 PointT p1, p2, p3, p4, p5;
1167 double minX, minY, maxX, maxY;
1168 maxX = dist * tan(std::atan(
width / (2.0 * focal)));
1170 maxY = dist * tan(std::atan(
height / (2.0 * focal)));
1184 p1 = pcl::transformPoint(p1, cam.pose);
1185 p2 = pcl::transformPoint(p2, cam.pose);
1186 p3 = pcl::transformPoint(p3, cam.pose);
1187 p4 = pcl::transformPoint(p4, cam.pose);
1188 p5 = pcl::transformPoint(p5, cam.pose);
1189 std::stringstream ss;
1190 ss <<
"Cam #" << i + 1;
1191 visu.addText3D(ss.str(), p1, 0.1, 1.0, 1.0, 1.0, ss.str());
1194 ss <<
"camera_" << i <<
"line1";
1195 visu.addLine(p1, p2, ss.str());
1197 ss <<
"camera_" << i <<
"line2";
1198 visu.addLine(p1, p3, ss.str());
1200 ss <<
"camera_" << i <<
"line3";
1201 visu.addLine(p1, p4, ss.str());
1203 ss <<
"camera_" << i <<
"line4";
1204 visu.addLine(p1, p5, ss.str());
1206 ss <<
"camera_" << i <<
"line5";
1207 visu.addLine(p2, p5, ss.str());
1209 ss <<
"camera_" << i <<
"line6";
1210 visu.addLine(p5, p4, ss.str());
1212 ss <<
"camera_" << i <<
"line7";
1213 visu.addLine(p4, p3, ss.str());
1215 ss <<
"camera_" << i <<
"line8";
1216 visu.addLine(p3, p2, ss.str());
1220 visu.addCoordinateSystem(1.0,
"global");
1223 pcl::visualization::PointCloudColorHandlerGenericField<PointT>
1224 color_handler(cloud,
"z");
1225 visu.addPointCloud(cloud, color_handler,
"cloud");
1236 void showTextureMesh(
const PCLTextureMesh::ConstPtr textureMesh) {
1238 pcl::visualization::PCLVisualizer visu(
"TextureMesh");
1241 visu.addCoordinateSystem(1.0,
"global");
1244 visu.addTextureMesh(*textureMesh,
"texture");
1254 std::ifstream& GotoLine(std::ifstream& file,
unsigned int num) {
1255 file.seekg(std::ios::beg);
1256 for (
unsigned int i = 0; i < num - 1; ++i) {
1257 file.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
1263 bool readCamPoseFile(std::string
filename,
1264 pcl::TextureMapping<PointT>::Camera& cam) {
1265 std::ifstream myReadFile;
1266 myReadFile.open(
filename.c_str(), std::ios::in);
1267 if (!myReadFile.is_open()) {
1271 myReadFile.seekg(ios::beg);
1276 GotoLine(myReadFile, 2);
1278 cam.pose(0, 3) = val;
1280 cam.pose(1, 3) = val;
1282 cam.pose(2, 3) = val;
1285 GotoLine(myReadFile, 7);
1288 cam.pose(0, 0) = val;
1290 cam.pose(0, 1) = val;
1292 cam.pose(0, 2) = val;
1295 cam.pose(1, 0) = val;
1297 cam.pose(1, 1) = val;
1299 cam.pose(1, 2) = val;
1302 cam.pose(2, 0) = val;
1304 cam.pose(2, 1) = val;
1306 cam.pose(2, 2) = val;
1308 cam.pose(3, 0) = 0.0;
1309 cam.pose(3, 1) = 0.0;
1310 cam.pose(3, 2) = 0.0;
1311 cam.pose(3, 3) = 1.0;
1314 GotoLine(myReadFile, 12);
1316 cam.focal_length = val;
1329 pcl::TextureMapping<PointT>::Camera& cam) {
1331 Eigen::Matrix4f camera_pose = pinholeCamera.
extrinsic_.cast<
float>();
1332 cam.pose.matrix() = camera_pose;
1337 cam.focal_length = focal_length.second;
1338 cam.focal_length_w = focal_length.first;
1339 cam.focal_length_h = focal_length.second;
1342 cam.center_w = center.first;
1343 cam.center_h = center.second;
1351 const std::string& filePath,
1356 CVLog::Print(
"Loading mesh from file %s...", filePath.c_str());
1358 PCLMesh::Ptr triangles(
new PCLMesh);
1359 pcl::io::loadPolygonFilePLY(filePath.c_str(), *triangles);
1365 pcl::texture_mapping::CameraVector my_cams;
1366 for (std::size_t i = 0; i < cameraTrajectory.
parameters_.size(); i++) {
1367 pcl::TextureMapping<PointT>::Camera cam;
1368 ConvertToPCLCamPose(cameraTrajectory.
parameters_[i], cam);
1369 cam.texture_file = cameraTrajectory.
parameters_[i].texture_file_;
1370 my_cams.push_back(cam);
1385 CVLog::Print(
"Loading mesh from file %s...", filePath.c_str());
1388 PCLMesh::Ptr triangles(
new PCLMesh);
1389 pcl::io::loadPolygonFilePLY(filePath.c_str(), *triangles);
1395 pcl::texture_mapping::CameraVector my_cams;
1397 std::string extension(
"txt");
1398 std::vector<std::string> file_names;
1401 for (std::size_t i = 0; i < file_names.size(); i++) {
1402 pcl::TextureMapping<PointT>::Camera cam;
1403 readCamPoseFile(file_names[i], cam);
1406 my_cams.push_back(cam);
1418 const PCLMesh::ConstPtr& triangles,
1419 const pcl::texture_mapping::CameraVector& cameras,
1427 mesh->cloud = triangles->cloud;
1428 std::vector<pcl::Vertices> polygons;
1431 polygons.resize(triangles->polygons.size());
1432 for (std::size_t i = 0; i < triangles->polygons.size(); ++i) {
1433 polygons[i] = triangles->polygons[i];
1435 mesh->tex_polygons.push_back(polygons);
1438 "[PclTools::CreateTexturingMesh] Input mesh contains %i faces "
1440 mesh->tex_polygons[0].size(),
1441 static_cast<std::size_t
>(cloud->size()));
1448 "Displaying cameras. Press \'q\' to continue texture mapping");
1449 showCameras(cameras, cloud);
1453 mesh->tex_materials.resize(cameras.size() + 1);
1454 for (std::size_t i = 0; i <= cameras.size(); ++i) {
1455 pcl::TexMaterial mesh_material;
1456 mesh_material.tex_Ka.r = 0.2f;
1457 mesh_material.tex_Ka.g = 0.2f;
1458 mesh_material.tex_Ka.b = 0.2f;
1460 mesh_material.tex_Kd.r = 0.8f;
1461 mesh_material.tex_Kd.g = 0.8f;
1462 mesh_material.tex_Kd.b = 0.8f;
1464 mesh_material.tex_Ks.r = 1.0f;
1465 mesh_material.tex_Ks.g = 1.0f;
1466 mesh_material.tex_Ks.b = 1.0f;
1468 mesh_material.tex_d = 1.0f;
1469 mesh_material.tex_Ns = 75.0f;
1470 mesh_material.tex_illum = 2;
1472 std::stringstream tex_name;
1473 tex_name <<
"material_" << i;
1474 tex_name >> mesh_material.tex_name;
1476 if (i < cameras.size()) {
1477 mesh_material.tex_file = cameras[i].texture_file;
1479 mesh_material.tex_file = cameras[0].texture_file;
1482 mesh->tex_materials[i] = mesh_material;
1489 pcl::TextureMapping<PointT>
1491 tm.textureMeshwithMultipleCameras(*mesh, cameras);
1495 for (std::size_t i = 0; i <= cameras.size(); ++i) {
1496 CVLog::Print(
"Sub mesh %i contains %i faces and %i UV coordinates.",
1497 i, mesh->tex_polygons[i].size(),
1498 mesh->tex_coordinates[i].size());
1506 pcl::NormalEstimation<PointT, NormalT> n;
1508 pcl::search::KdTree<PointT>::Ptr tree(
new pcl::search::KdTree<PointT>);
1509 tree->setInputCloud(cloud);
1510 n.setInputCloud(cloud);
1511 n.setSearchMethod(tree);
1517 pcl::concatenateFields(*cloud, *
normals, *cloud_with_normals);
filament::Texture::InternalFormat format
pcl::PointCloud< PointNT > PointCloudNormal
pcl::PointCloud< PointT > PointCloudT
pcl::TextureMesh PCLTextureMesh
pcl::PointCloud< NormalT > CloudNormal
static bool Print(const char *format,...)
Prints out a formatted message in console.
static bool Error(const char *format,...)
Display an error dialog with formatted message.
Camera (projective) sensor.
const cloudViewer::geometry::LineSet & getNearPlane() const
const cloudViewer::geometry::LineSet & getSideLines() const
const cloudViewer::geometry::LineSet & getArrow() const
const cloudViewer::geometry::LineSet & getAxis() const
QSharedPointer< ccColorScale > Shared
Shared pointer type.
std::set< Label > LabelSet
Type of a list of custom labels.
virtual bool hasColors() const
Returns whether colors are enabled or not.
Ground-based Laser sensor.
const ecvOrientedBBox & getSensorHead() const
const cloudViewer::geometry::LineSet & getSensorLegLines() const
const cloudViewer::geometry::LineSet & getSensorAxis() const
void apply(float vec[3]) const
Applies transformation to a 3D vector (in place) - float version.
Double version of ccGLMatrixTpl.
bool isInRange(ScalarType val) const
Returns whether a value is inside range or not.
A scalar field associated to display-related parameters.
const ccColorScale::Shared & getColorScale() const
Returns associated color scale.
bool logScale() const
Returns whether scalar field is logarithmic or not.
double getGlobalShift() const
Returns the global shift (if any)
const Range & saturationRange() const
Access to the range of saturation values.
const Histogram & getHistogram() const
Returns associated histogram values (for display)
const Range & displayRange() const
Access to the range of displayed values.
const ecvColor::Rgb * getColor(ScalarType value) const
bool symmetricalScale() const
Returns whether the color scale s symmetrical or not.
bool areNaNValuesShownInGrey() const
Returns whether NaN values are displayed in gray or hidden.
bool isZeroAlwaysShown() const
Returns whether 0 should always appear in associated color ramp or not.
const char * getName() const
Returns scalar field name.
int height_
Height of the image.
int width_
Width of the image.
std::pair< double, double > GetFocalLength() const
Returns the focal length in a tuple of X-axis and Y-axis focal lengths.
std::pair< double, double > GetPrincipalPoint() const
Contains both intrinsic and extrinsic pinhole camera parameters.
PinholeCameraIntrinsic intrinsic_
PinholeCameraIntrinsic object.
Eigen::Matrix4d_u extrinsic_
Camera extrinsic parameters.
std::vector< PinholeCameraParameters > parameters_
List of PinholeCameraParameters objects.
LineSet define a sets of lines in 3D. A typical application is to display the point cloud corresponde...
std::pair< Eigen::Vector3d, Eigen::Vector3d > GetLineCoordinate(size_t line_index) const
Returns the coordinates of the line at the given index.
static std::shared_ptr< LineSet > CreateFromOrientedBoundingBox(const ecvOrientedBBox &box)
Factory function to create a LineSet from an OrientedBoundingBox.
std::vector< Eigen::Vector3d > points_
Points coordinates.
std::vector< Eigen::Vector3d > colors_
RGB colors of lines.
std::vector< Eigen::Vector2i > lines_
Lines denoted by the index of points forming the line.
constexpr static RgbTpl FromEigen(const Eigen::Vector3d &t)
static Eigen::Vector3d ToEigen(const Type col[3])
bool ListFilesInDirectoryWithExtension(const std::string &directory, const std::string &extname, std::vector< std::string > &filenames)
std::string GetFileBaseName(const std::string &filename)
Generic file read and write utility for python interface.
constexpr Rgb red(MAX, 0, 0)
constexpr Rgb lightGrey(static_cast< ColorCompType >(MAX *0.8), static_cast< ColorCompType >(MAX *0.8), static_cast< ColorCompType >(MAX *0.8))
constexpr Rgb green(0, MAX, 0)
constexpr Rgb yellow(MAX, MAX, 0)
Eigen::Matrix< Index, 2, 1 > Vector2i
float renderZoom
Current zoom (screen to file rendering mode)
ccScalarField * sfColorScaleToDisplay
Currently displayed color scale (the corresponding scalar field in fact)
Simple histogram structure.
unsigned maxValue
Max histogram value.
unsigned displayedNumPrecision
Displayed numbers precision.
ecvColor::Rgbub textDefaultCol
Default text color.
unsigned defaultFontSize
Default displayed font size.
unsigned colorScaleRampWidth
Color scale ramp width (for display)
bool colorScaleShowHistogram
Color scale option: show histogram next to color ramp.
vlabel(int y, int y1, int y2, double v)
#define VTK_CREATE(type, name)