37 #include <pcl/io/pcd_io.h>
38 #include <pcl/point_cloud.h>
39 #include <pcl/point_types.h>
42 #include <vtkFieldData.h>
43 #include <vtkGenericOpenGLRenderWindow.h>
44 #include <vtkPolyData.h>
45 #include <vtkStringArray.h>
66 renderWindow->AddRenderer(renderer);
67 auto interactorStyle =
70 renderer, renderWindow, interactorStyle,
"3Dviewer",
false));
106 int viewport =
context.defaultViewPort;
108 bool hasRedrawn =
false;
118 if (ecvCloud->
isRedraw() || firstShow) {
120 PCLCloud::Ptr pclCloud =
131 if (!updateEntityColor(localContext, ecvCloud)) {
132 PCLCloud::Ptr pclCloud =
143 PCLCloud::Ptr pointNormals =
160 if (firstShow || hasRedrawn) {
169 for (
unsigned i = 0; i < numSFs; ++i) {
171 viewID, ecvCloud,
static_cast<int>(i), viewport);
179 if (actor && actor->GetMapper()) {
180 vtkPolyData* polyData = vtkPolyData::SafeDownCast(
181 actor->GetMapper()->GetInput());
183 vtkFieldData* fieldData = polyData->GetFieldData();
185 vtkStringArray* datasetNameArray =
186 vtkStringArray::SafeDownCast(
187 fieldData->GetAbstractArray(
189 if (!datasetNameArray) {
191 QString cloudName = ecvCloud->
getName();
192 if (!cloudName.isEmpty()) {
194 newDatasetNameArray =
198 newDatasetNameArray->SetName(
"DatasetName");
199 newDatasetNameArray->SetNumberOfTuples(1);
200 newDatasetNameArray->SetValue(
201 0, cloudName.toStdString());
202 fieldData->AddArray(newDatasetNameArray);
205 QString(
"[PCLDisplayTools] Added "
206 "DatasetName for point "
230 if ((!
context.drawParam.showColors && !
context.drawParam.showSF) ||
235 pointUniqueColor.
r, pointUniqueColor.
g, pointUniqueColor.
b,
252 if (applyMaterials || showTextures) {
261 QString(
"Mesh texture has not been shown, please toggle it "
269 int viewport =
context.defaultViewPort;
280 if (mesh->
isRedraw() || firstShow) {
282 "[PCLDisplayTools::drawMesh] Entering render block "
283 "(isRedraw=%d || firstShow=%d)",
289 "[PCLDisplayTools::drawMesh] Failed to get point cloud "
296 bool lodEnabled =
false;
301 "[PCLDisplayTools::drawMesh] applyMaterials=%d, "
303 applyMaterials, showTextures);
306 if (applyMaterials || showTextures) {
311 "[PCLDisplayTools::drawMesh] Failed to add texture "
312 "mesh directly, falling back to PCLTextureMesh");
314 PCLTextureMesh::Ptr textureMesh =
320 "[PCLDisplayTools::drawMesh] Failed to create "
321 "PCLTextureMesh, falling back to regular mesh");
322 PCLMesh::Ptr pclMesh =
324 if (!pclMesh)
return;
330 PCLMesh::Ptr pclMesh =
332 if (!pclMesh)
return;
339 if (actor && actor->GetMapper() &&
340 mesh->
getName().length() > 0) {
341 vtkPolyData* polyData = vtkPolyData::SafeDownCast(
342 actor->GetMapper()->GetInput());
344 QString meshName = mesh->
getName();
346 QString(
"[PCLDisplayTools::drawMesh] "
347 "Adding DatasetName to "
348 "non-textured mesh: '%1'")
353 datasetNameArray->SetName(
"DatasetName");
354 datasetNameArray->SetNumberOfTuples(1);
355 datasetNameArray->SetValue(0, meshName.toStdString());
356 polyData->GetFieldData()->AddArray(datasetNameArray);
364 "[PCLDisplayTools::drawMesh] Update path: updating "
367 if (!updateEntityColor(
context, ecvCloud)) {
368 if (applyMaterials || showTextures) {
373 "[PCLDisplayTools::drawMesh] Updating textures "
379 "[PCLDisplayTools::drawMesh] Update "
384 PCLMesh::Ptr pclMesh =
386 if (!pclMesh)
return;
402 if (ccMeshObj && (firstShow || mesh->
isRedraw())) {
406 if ((!
context.drawParam.showColors && !
context.drawParam.showSF) ||
411 meshColor.
r, meshColor.
g, meshColor.
b, viewID, viewport);
421 int viewport =
context.defaultViewPort;
423 if (polyline->
isRedraw() || firstShow) {
425 if (!pclPolygon)
return;
433 polygonColor.
b, viewID, viewport);
444 int viewport =
context.defaultViewPort;
446 if (lineset->
isRedraw() || firstShow) {
456 polygonColor.
b, viewID,
473 bool imageExists = !firstShow;
479 bool needsImageReload = firstShow || (
image->isRedraw() && !imageExists);
481 double opacity =
image->getAlpha();
483 if (needsImageReload) {
484 const QImage& qimage =
image->data();
485 if (qimage.isNull()) {
487 "[PCLDisplayTools::drawImage] Failed to get image data!");
492 "[PCLDisplayTools::drawImage] Reloading image data: %d x %d, "
493 "opacity: %f, redraw: %d, firstShow: %d, isEnabled: %d",
495 image->isRedraw(), firstShow,
image->isEnabled());
504 "[PCLDisplayTools::drawImage] Updating opacity only for image "
507 viewID.c_str(), opacity);
520 int viewport =
context.defaultViewPort;
522 if (sensor->
isRedraw() || firstShow) {
551 reinterpret_cast<vtkPolyDataMapper*
>(modelActor->GetMapper())
553 if (!polydata)
return (
false);
560 unsigned old_points_num =
561 static_cast<unsigned>(polydata->GetNumberOfPoints());
562 unsigned new_points_num = converter.getvisibilityNum();
563 if (old_points_num != new_points_num) {
571 if (converter.getvtkScalars(scalars,
context.drawParam.showSF)) {
573 polydata->GetPointData()->SetScalars(scalars);
574 scalars->GetRange(minmax);
579 #if VTK_RENDERING_BACKEND_OPENGL_VERSION < 2
580 modelActor->GetMapper()->ImmediateModeRenderingOff();
582 modelActor->GetMapper()->SetScalarRange(minmax);
584 #if VTK_MAJOR_VERSION < 6
585 reinterpret_cast<vtkPolyDataMapper*
>(modelActor->GetMapper())
586 ->SetInput(polydata);
588 reinterpret_cast<vtkPolyDataMapper*
>(modelActor->GetMapper())
589 ->SetInputData(polydata);
605 if (!ecvCloud)
return;
607 drawPointCloud(
context, ecvCloud);
615 "[PCLDisplayTools::draw] Failed to cast to ccGenericMesh!");
623 if (!tempPolyline)
return;
624 drawPolygon(
context, tempPolyline);
629 if (!lineset)
return;
655 if (firstShow)
return true;
670 reinterpret_cast<vtkPolyDataMapper*
>(modelActor->GetMapper())
677 unsigned old_points_num =
678 static_cast<unsigned>(polydata->GetNumberOfPoints());
680 if (old_points_num != new_points_num) {
685 polydata->GetBounds(bounds);
686 CCVector3 minCorner(bounds[0], bounds[2], bounds[4]);
687 CCVector3 maxCorner(bounds[1], bounds[3], bounds[5]);
688 ccBBox oldBBox(minCorner, maxCorner);
707 int viewport =
context.defaultViewPort;
714 colf.
r, colf.
g, colf.
b, bboxID, viewport);
719 pcl::visualization::PCL_VISUALIZER_REPRESENTATION,
720 pcl::visualization::PCL_VISUALIZER_REPRESENTATION_WIREFRAME,
737 pcl::visualization::PCL_VISUALIZER_OPACITY,
context.opacity,
745 int viewport =
context.defaultViewPort;
835 std::string normalViewId =
852 switch (param.
type) {
890 unsigned char lineWidth =
895 lineColor.g, lineColor.b, viewID,
933 param.
p2.x(), param.
p2.y(),
944 if (poly->
size() <= 1) {
950 "[PCLDisplayTools::drawWidgets] draw mode is "
951 "incompatible with entity mode!");
964 for (
unsigned i = 1; i < poly->
size(); ++i) {
969 static_cast<int>(p1->
y),
970 static_cast<int>(p2->
x),
971 static_cast<int>(p2->
y),
992 if (poly->
size() <= 1) {
1007 param.
p2.x(), param.
p2.y(),
1013 param.
p3.x(), param.
p3.y(),
1016 if (param.
p4.x() >= 0 && param.
p4.y() >= 0) {
1019 param.
p3.x(), param.
p3.y(), param.
p4.x(),
1024 param.
p4.x(), param.
p4.y(), param.
p1.x(),
1030 param.
p3.x(), param.
p3.y(), param.
p1.x(),
1048 int minX = std::max(param.
rect.x(), 0);
1049 int maxX = std::min(minX + param.
rect.width(),
1051 int minY = std::max(param.
rect.y(), 0);
1052 int maxY = std::min(minY + param.
rect.height(),
1057 minX, maxX, minY, maxY, param.
color.
r,
1078 if (param.
image.isNull())
return;
1081 param.
rect.y(), viewID,
1101 textColor.
g, textColor.
b, viewID, textParam.
opacity,
1102 textParam.
font.pointSize(), textParam.
font.bold());
1146 bool renderOverlayItems,
1150 return m_visualizer3D->renderToImage(zoomFactor, renderOverlayItems,
1155 "[PCLDisplayTools::renderToImage] PCLVis Initialization "
1156 "failed! (not enough memory?)");
1176 Eigen::Matrix4d projMat;
1177 m_visualizer3D->getCamera(viewport).computeProjectionMatrix(projMat);
1179 double* tempArray = projMat.data();
1180 projArray[0] = tempArray[0];
1181 projArray[1] = tempArray[1];
1182 projArray[2] = tempArray[2];
1183 projArray[3] = tempArray[3];
1184 projArray[4] = tempArray[4];
1185 projArray[5] = tempArray[5];
1186 projArray[6] = tempArray[6];
1187 projArray[7] = tempArray[7];
1188 projArray[8] = tempArray[8];
1189 projArray[9] = tempArray[9];
1190 projArray[10] = tempArray[10];
1191 projArray[11] = tempArray[11];
1192 projArray[12] = tempArray[12];
1193 projArray[13] = tempArray[13];
1194 projArray[14] = tempArray[14];
1195 projArray[15] = tempArray[15];
1199 Eigen::Matrix4d viewMat;
1202 double* tempArray = viewMat.data();
1203 ViewArray[0] = tempArray[0];
1204 ViewArray[1] = tempArray[1];
1205 ViewArray[2] = tempArray[2];
1206 ViewArray[3] = tempArray[3];
1207 ViewArray[4] = tempArray[4];
1208 ViewArray[5] = tempArray[5];
1209 ViewArray[6] = tempArray[6];
1210 ViewArray[7] = tempArray[7];
1211 ViewArray[8] = tempArray[8];
1212 ViewArray[9] = tempArray[9];
1213 ViewArray[10] = tempArray[10];
1214 ViewArray[11] = tempArray[11];
1215 ViewArray[12] = tempArray[12];
1216 ViewArray[13] = tempArray[13];
1217 ViewArray[14] = tempArray[14];
1218 ViewArray[15] = tempArray[15];
1228 const std::string& viewID,
1244 static_cast<unsigned char>(param.
lineWidth), viewId,
1253 colf.
r, colf.
g, colf.
b, viewId, viewport);
1391 int viewport)
const {
constexpr double EPSILON_VALUE
Vector3Tpl< double > CCVector3d
Double 3D Vector.
std::shared_ptr< core::Tensor > image
static bool PrintDebug(const char *format,...)
Same as Print, but works only in Debug mode.
static bool Warning(const char *format,...)
Prints out a formatted warning message in console.
static bool PrintVerbose(const char *format,...)
Prints out a verbose formatted message in console.
static bool Error(const char *format,...)
Display an error dialog with formatted message.
CC to PCL cloud converter.
PCLCloud::Ptr getPointNormals() const
PCLCloud::Ptr getAsSM(std::list< std::string > &requested_fields) const
PCLPolygon::Ptr getPclPolygon(ccPolyline *polyline) const
unsigned getvisibilityNum() const
PCLMesh::Ptr getPclMesh(ccGenericMesh *mesh)
PCLTextureMesh::Ptr getPclTextureMesh(ccGenericMesh *mesh)
virtual bool colorsShown() const
Returns whether colors are shown or not.
virtual bool sfShown() const
Returns whether active scalar field is visible.
virtual bool isColorOverridden() const
virtual bool isRedraw() const
Returns whether entity is to be redraw.
virtual const ecvColor::Rgb & getTempColor() const
Returns current temporary (unique) color.
T * data()
Returns a pointer to internal data.
Double version of ccGLMatrixTpl.
virtual bool materialsShown() const
Sets whether textures/material should be displayed or not.
virtual bool hasTextures() const =0
Returns whether textures are available for this mesh.
virtual const ccMaterialSet * getMaterialSet() const =0
virtual bool hasMaterials() const =0
ccBBox getOwnBB(bool withGLFeatures=false) override
Returns the entity's own bounding-box.
static ccPolyline * ToPolyline(ccHObject *obj)
Converts current object to ccPolyline (if possible)
static ccImage * ToImage(ccHObject *obj)
static cloudViewer::geometry::LineSet * ToLineSet(ccHObject *obj)
static ccGenericMesh * ToGenericMesh(ccHObject *obj)
Converts current object to ccGenericMesh (if possible)
static ccSensor * ToSensor(ccHObject *obj)
Converts current object to ccSensor (if possible)
static ccPointCloud * ToPointCloud(ccHObject *obj, bool *isLockedVertices=nullptr)
Converts current object to 'equivalent' ccPointCloud.
Hierarchical CLOUDVIEWER Object.
QString getViewId() const
Mesh (triangle) material.
virtual QString getName() const
Returns object name.
bool isA(CV_CLASS_ENUM type) const
bool isKindOf(CV_CLASS_ENUM type) const
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
int getCurrentDisplayedScalarFieldIndex() const
Returns the currently displayed scalar field index (or -1 if none)
bool is2DMode() const
Returns whether the polyline is considered as 2D or 3D.
const ecvColor::Rgb & getColor() const
Returns the polyline color.
Generic sensor interface.
const Vector3Tpl< T > & maxCorner() const
Returns max corner (const)
const Vector3Tpl< T > & minCorner() const
Returns min corner (const)
unsigned getNumberOfScalarFields() const
Returns the number of associated (and active) scalar fields.
bool isClosed() const
Returns whether the polyline is closed or not.
unsigned size() const override
Returns the number of points.
const CCVector3 * getPoint(unsigned index) const override
Returns the ith point.
LineSet define a sets of lines in 3D. A typical application is to display the point cloud corresponde...
bool HasColors() const
Returns true if the objects lines contains colors.
@ ECV_POINTSSIZE_PROPERTY
Rgb FromRgbafToRgb(const Rgbaf &color)
Conversion from Rgbaf.
constexpr Rgb green(0, MAX, 0)
Rgbf FromRgb(const Rgb &color)
Eigen::Array< unsigned char, 3, 1 > Vector3ub
Data Axes Grid properties structure Encapsulates all properties for vtkCubeAxesActor configuration.
PointCoordinateType lineWidth
QString viewId
Display scalar field (prioritary on colors)
bool showNorms
Display normals.
bool showSF
Display scalar field (prioritary on colors)