normals_actor_item.cpp
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Point Cloud Library (PCL) - www.pointclouds.org
00005  *  Copyright (c) 2012, Willow Garage, Inc.
00006  *  All rights reserved.
00007  *
00008  *  Redistribution and use in source and binary forms, with or without
00009  *  modification, are permitted provided that the following conditions
00010  *  are met:
00011  *
00012  *   * Redistributions of source code must retain the above copyright
00013  *     notice, this list of conditions and the following disclaimer.
00014  *   * Redistributions in binary form must reproduce the above
00015  *     copyright notice, this list of conditions and the following
00016  *     disclaimer in the documentation and/or other materials provided
00017  *     with the distribution.
00018  *   * Neither the name of Willow Garage, Inc. nor the names of its
00019  *     contributors may be used to endorse or promote products derived
00020  *     from this software without specific prior written permission.
00021  *
00022  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033  *  POSSIBILITY OF SUCH DAMAGE.
00034  *
00035  */
00036 
00037 #include <pcl/apps/modeler/normals_actor_item.h>
00038 
00039 #include <pcl/apps/modeler/cloud_mesh.h>
00040 #include <pcl/filters/filter_indices.h>
00041 
00042 #include <vtkLODActor.h>
00043 #include <vtkPolyData.h>
00044 #include <vtkCellArray.h>
00045 #include <vtkDataSetMapper.h>
00046 #include <vtkPointData.h>
00047 
00049 pcl::modeler::NormalsActorItem::NormalsActorItem(QTreeWidgetItem* parent,
00050                                                const boost::shared_ptr<CloudMesh>& cloud_mesh,
00051                                                const vtkSmartPointer<vtkRenderWindow>& render_window)
00052   :ChannelActorItem(parent, cloud_mesh, render_window, vtkSmartPointer<vtkLODActor>::New(), "Normals"),
00053   level_(10), scale_(0.1)
00054 {
00055 }
00056 
00058 pcl::modeler::NormalsActorItem::~NormalsActorItem ()
00059 {
00060 
00061 }
00062 
00064 void
00065 pcl::modeler::NormalsActorItem::createNormalLines()
00066 {
00067   vtkPoints* points = poly_data_->GetPoints();
00068   vtkCellArray* lines = poly_data_->GetLines();
00069   lines->Reset();
00070 
00071   CloudMesh::PointCloudConstPtr cloud = cloud_mesh_->getCloud();
00072   if (cloud->empty())
00073     return;
00074 
00075   if (points->GetData() == NULL)
00076     points->SetData(vtkSmartPointer<vtkFloatArray>::New ());
00077 
00078   vtkFloatArray* data = dynamic_cast<vtkFloatArray*>(points->GetData());
00079   data->SetNumberOfComponents (3);
00080 
00081   if (cloud->is_dense)
00082   {
00083     vtkIdType nr_normals = static_cast<vtkIdType> ((cloud->points.size () - 1) / level_ + 1);
00084     data->SetNumberOfValues(2*3*nr_normals);
00085     for (vtkIdType i = 0, j = 0; j < nr_normals; j++, i = static_cast<vtkIdType> (j * level_))
00086     {
00087       const CloudMesh::PointT& p = cloud->points[i];
00088       data->SetValue(2*j*3 + 0, p.x);
00089       data->SetValue(2*j*3 + 1, p.y);
00090       data->SetValue(2*j*3 + 2, p.z);
00091       data->SetValue(2*j*3 + 3, float (p.x + p.normal_x*scale_));
00092       data->SetValue(2*j*3 + 4, float (p.y + p.normal_y*scale_));
00093       data->SetValue(2*j*3 + 5, float (p.z + p.normal_z*scale_));
00094 
00095       lines->InsertNextCell(2);
00096       lines->InsertCellPoint(2*j);
00097       lines->InsertCellPoint(2*j + 1);
00098     }
00099   }
00100   else
00101   {
00102     pcl::IndicesPtr indices(new std::vector<int>());
00103     pcl::removeNaNFromPointCloud(*cloud, *indices);
00104 
00105     vtkIdType nr_normals = static_cast<vtkIdType> ((indices->size () - 1) / level_ + 1);
00106     data->SetNumberOfValues(2*3*nr_normals);
00107     for (vtkIdType i = 0, j = 0; j < nr_normals; j++, i = static_cast<vtkIdType> (j * level_))
00108     {
00109       const CloudMesh::PointT& p= cloud->points[(*indices)[i]];
00110       data->SetValue (2*j*3 + 0, p.x);
00111       data->SetValue (2*j*3 + 1, p.y);
00112       data->SetValue (2*j*3 + 2, p.z);
00113       data->SetValue (2*j*3 + 3, float (p.x + p.normal_x*scale_));
00114       data->SetValue (2*j*3 + 4, float (p.y + p.normal_y*scale_));
00115       data->SetValue (2*j*3 + 5, float (p.z + p.normal_z*scale_));
00116 
00117       lines->InsertNextCell(2);
00118       lines->InsertCellPoint(2*j);
00119       lines->InsertCellPoint(2*j + 1);
00120     }
00121   }
00122 
00123   return;
00124 }
00125 
00127 void
00128 pcl::modeler::NormalsActorItem::initImpl()
00129 {
00130   vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
00131   points->SetDataTypeToFloat ();
00132   vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New();
00133 
00134   poly_data_->SetPoints(points);
00135   poly_data_->SetLines(lines);
00136 
00137   createNormalLines();
00138 
00139   vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New();
00140   mapper->SetInput(poly_data_);
00141 
00142   vtkSmartPointer<vtkDataArray> scalars;
00143   cloud_mesh_->getColorScalarsFromField(scalars, color_scheme_);
00144   poly_data_->GetPointData ()->SetScalars (scalars);
00145   double minmax[2];
00146   scalars->GetRange(minmax);
00147   mapper->SetScalarRange(minmax);
00148 
00149   mapper->SetColorModeToMapScalars();
00150   mapper->SetScalarModeToUsePointData();
00151 
00152   vtkSmartPointer<vtkLODActor> actor = vtkSmartPointer<vtkLODActor>(dynamic_cast<vtkLODActor*>(actor_.GetPointer()));
00153   actor->SetMapper(mapper);
00154 }
00155 
00157 void
00158 pcl::modeler::NormalsActorItem::updateImpl()
00159 {
00160   createNormalLines();
00161 
00162   vtkSmartPointer<vtkDataArray> scalars;
00163   cloud_mesh_->getColorScalarsFromField(scalars, color_scheme_);
00164   poly_data_->GetPointData ()->SetScalars (scalars);
00165   double minmax[2];
00166   scalars->GetRange(minmax);
00167   actor_->GetMapper()->SetScalarRange(minmax);
00168 
00169   poly_data_->Update();
00170 
00171   return;
00172 }
00173 
00175 void
00176 pcl::modeler::NormalsActorItem::prepareContextMenu(QMenu* ) const
00177 {
00178 
00179 }
00180 
00182 void
00183 pcl::modeler::NormalsActorItem::prepareProperties(ParameterDialog* )
00184 {
00185 
00186 }
00187 
00189 void
00190 pcl::modeler::NormalsActorItem::setProperties()
00191 {
00192 
00193 }


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:26:07