removed trailing spaces
This commit is contained in:
@@ -327,7 +327,7 @@ struct cv::viz::WCloudCollection::CreateCloudWidget
|
||||
vertices->SetCells(nr_points, cells);
|
||||
return polydata;
|
||||
}
|
||||
|
||||
|
||||
static void createMapper(vtkSmartPointer<vtkLODActor> actor, vtkSmartPointer<vtkPolyData> poly_data, Vec3d& minmax)
|
||||
{
|
||||
vtkDataSetMapper *mapper = vtkDataSetMapper::SafeDownCast(actor->GetMapper());
|
||||
@@ -349,17 +349,17 @@ struct cv::viz::WCloudCollection::CreateCloudWidget
|
||||
mapper_new->SetInterpolateScalarsBeforeMapping(interpolation);
|
||||
mapper_new->ScalarVisibilityOn();
|
||||
mapper_new->ImmediateModeRenderingOff();
|
||||
|
||||
|
||||
actor->SetNumberOfCloudPoints(int(std::max<vtkIdType>(1, poly_data->GetNumberOfPoints() / 10)));
|
||||
actor->GetProperty()->SetInterpolationToFlat();
|
||||
actor->GetProperty()->BackfaceCullingOn();
|
||||
actor->SetMapper(mapper_new);
|
||||
return ;
|
||||
}
|
||||
|
||||
|
||||
vtkPolyData *data = vtkPolyData::SafeDownCast(mapper->GetInput());
|
||||
CV_Assert("Cloud Widget without data" && data);
|
||||
|
||||
|
||||
vtkSmartPointer<vtkAppendPolyData> appendFilter = vtkSmartPointer<vtkAppendPolyData>::New();
|
||||
#if VTK_MAJOR_VERSION <= 5
|
||||
appendFilter->AddInputConnection(mapper->GetInput()->GetProducerPort());
|
||||
@@ -369,7 +369,7 @@ struct cv::viz::WCloudCollection::CreateCloudWidget
|
||||
appendFilter->AddInputData(poly_data);
|
||||
#endif
|
||||
mapper->SetInputConnection(appendFilter->GetOutputPort());
|
||||
|
||||
|
||||
// Update the number of cloud points
|
||||
vtkIdType old_cloud_points = actor->GetNumberOfCloudPoints();
|
||||
actor->SetNumberOfCloudPoints(int(std::max<vtkIdType>(1, old_cloud_points+poly_data->GetNumberOfPoints() / 10)));
|
||||
@@ -389,7 +389,7 @@ void cv::viz::WCloudCollection::addCloud(InputArray _cloud, InputArray _colors,
|
||||
Mat colors = _colors.getMat();
|
||||
CV_Assert(cloud.type() == CV_32FC3 || cloud.type() == CV_64FC3 || cloud.type() == CV_32FC4 || cloud.type() == CV_64FC4);
|
||||
CV_Assert(colors.type() == CV_8UC3 && cloud.size() == colors.size());
|
||||
|
||||
|
||||
if (cloud.isContinuous() && colors.isContinuous())
|
||||
{
|
||||
cloud.reshape(cloud.channels(), 1);
|
||||
@@ -410,12 +410,12 @@ void cv::viz::WCloudCollection::addCloud(InputArray _cloud, InputArray _colors,
|
||||
|
||||
// Assign the colors
|
||||
polydata->GetPointData()->SetScalars(scalars);
|
||||
|
||||
|
||||
// Transform the poly data based on the pose
|
||||
vtkSmartPointer<vtkTransform> transform = vtkSmartPointer<vtkTransform>::New();
|
||||
transform->PreMultiply();
|
||||
transform->SetMatrix(convertToVtkMatrix(pose.matrix));
|
||||
|
||||
|
||||
vtkSmartPointer<vtkTransformPolyDataFilter> transform_filter = vtkSmartPointer<vtkTransformPolyDataFilter>::New();
|
||||
transform_filter->SetTransform(transform);
|
||||
#if VTK_MAJOR_VERSION <= 5
|
||||
@@ -424,10 +424,10 @@ void cv::viz::WCloudCollection::addCloud(InputArray _cloud, InputArray _colors,
|
||||
transform_filter->SetInputData(polydata);
|
||||
#endif
|
||||
transform_filter->Update();
|
||||
|
||||
|
||||
vtkLODActor *actor = vtkLODActor::SafeDownCast(WidgetAccessor::getProp(*this));
|
||||
CV_Assert("Incompatible widget type." && actor);
|
||||
|
||||
|
||||
Vec3d minmax(scalars->GetRange());
|
||||
CreateCloudWidget::createMapper(actor, transform_filter->GetOutput(), minmax);
|
||||
}
|
||||
@@ -449,12 +449,12 @@ void cv::viz::WCloudCollection::addCloud(InputArray _cloud, const Color &color,
|
||||
|
||||
// Assign the colors
|
||||
polydata->GetPointData()->SetScalars(scalars);
|
||||
|
||||
|
||||
// Transform the poly data based on the pose
|
||||
vtkSmartPointer<vtkTransform> transform = vtkSmartPointer<vtkTransform>::New();
|
||||
transform->PreMultiply();
|
||||
transform->SetMatrix(convertToVtkMatrix(pose.matrix));
|
||||
|
||||
|
||||
vtkSmartPointer<vtkTransformPolyDataFilter> transform_filter = vtkSmartPointer<vtkTransformPolyDataFilter>::New();
|
||||
transform_filter->SetTransform(transform);
|
||||
#if VTK_MAJOR_VERSION <= 5
|
||||
@@ -463,10 +463,10 @@ void cv::viz::WCloudCollection::addCloud(InputArray _cloud, const Color &color,
|
||||
transform_filter->SetInputData(polydata);
|
||||
#endif
|
||||
transform_filter->Update();
|
||||
|
||||
|
||||
vtkLODActor *actor = vtkLODActor::SafeDownCast(WidgetAccessor::getProp(*this));
|
||||
CV_Assert("Incompatible widget type." && actor);
|
||||
|
||||
|
||||
Vec3d minmax(scalars->GetRange());
|
||||
CreateCloudWidget::createMapper(actor, transform_filter->GetOutput(), minmax);
|
||||
}
|
||||
@@ -634,7 +634,7 @@ struct cv::viz::WMesh::CopyImpl
|
||||
int index = 0;
|
||||
const _Tp* srow = source.ptr<_Tp>(0);
|
||||
const _Tp* mrow = nan_mask.ptr<_Tp>(0);
|
||||
|
||||
|
||||
for (int x = 0; x < source.cols; ++x, srow += s_chs, mrow += m_chs)
|
||||
{
|
||||
if (!isNan(mrow[0]) && !isNan(mrow[1]) && !isNan(mrow[2]))
|
||||
@@ -653,13 +653,13 @@ cv::viz::WMesh::WMesh(const Mesh3d &mesh)
|
||||
CV_Assert(mesh.cloud.rows == 1 && (mesh.cloud.type() == CV_32FC3 || mesh.cloud.type() == CV_64FC3 || mesh.cloud.type() == CV_32FC4 || mesh.cloud.type() == CV_64FC4));
|
||||
CV_Assert(mesh.colors.empty() || (mesh.colors.type() == CV_8UC3 && mesh.cloud.size() == mesh.colors.size()));
|
||||
CV_Assert(!mesh.polygons.empty() && mesh.polygons.type() == CV_32SC1);
|
||||
|
||||
|
||||
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
|
||||
vtkIdType nr_points = mesh.cloud.total();
|
||||
Mat look_up_mat(1, nr_points, CV_32SC1);
|
||||
int * look_up = look_up_mat.ptr<int>();
|
||||
points->SetNumberOfPoints(nr_points);
|
||||
|
||||
|
||||
// Copy data from cloud to vtkPoints
|
||||
if (mesh.cloud.depth() == CV_32F)
|
||||
{
|
||||
@@ -675,36 +675,36 @@ cv::viz::WMesh::WMesh(const Mesh3d &mesh)
|
||||
Vec3d *data_end = CopyImpl::copy(mesh.cloud, data_beg, look_up, mesh.cloud);
|
||||
nr_points = data_end - data_beg;
|
||||
}
|
||||
|
||||
|
||||
vtkSmartPointer<vtkUnsignedCharArray> scalars;
|
||||
|
||||
|
||||
if (!mesh.colors.empty())
|
||||
{
|
||||
Vec3b * colors_data = 0;
|
||||
colors_data = new Vec3b[nr_points];
|
||||
NanFilter::copyColor(mesh.colors, colors_data, mesh.cloud);
|
||||
|
||||
|
||||
scalars = vtkSmartPointer<vtkUnsignedCharArray>::New();
|
||||
scalars->SetNumberOfComponents(3);
|
||||
scalars->SetNumberOfTuples(nr_points);
|
||||
scalars->SetArray(colors_data->val, 3 * nr_points, 0);
|
||||
}
|
||||
|
||||
|
||||
points->SetNumberOfPoints(nr_points);
|
||||
|
||||
|
||||
vtkSmartPointer<vtkPointSet> data;
|
||||
|
||||
|
||||
if (mesh.polygons.size().area() > 1)
|
||||
{
|
||||
vtkSmartPointer<vtkCellArray> cell_array = vtkSmartPointer<vtkCellArray>::New();
|
||||
const int * polygons = mesh.polygons.ptr<int>();
|
||||
|
||||
|
||||
int idx = 0;
|
||||
int poly_size = mesh.polygons.total();
|
||||
for (int i = 0; i < poly_size; ++idx)
|
||||
{
|
||||
int n_points = polygons[i++];
|
||||
|
||||
|
||||
cell_array->InsertNextCell(n_points);
|
||||
for (int j = 0; j < n_points; ++j, ++idx)
|
||||
cell_array->InsertCellPoint(look_up[polygons[i++]]);
|
||||
@@ -717,7 +717,7 @@ cv::viz::WMesh::WMesh(const Mesh3d &mesh)
|
||||
|
||||
if (scalars)
|
||||
polydata->GetPointData()->SetScalars(scalars);
|
||||
|
||||
|
||||
data = polydata;
|
||||
}
|
||||
else
|
||||
@@ -726,20 +726,20 @@ cv::viz::WMesh::WMesh(const Mesh3d &mesh)
|
||||
vtkSmartPointer<vtkPolygon> polygon = vtkSmartPointer<vtkPolygon>::New();
|
||||
const int * polygons = mesh.polygons.ptr<int>();
|
||||
int n_points = polygons[0];
|
||||
|
||||
|
||||
polygon->GetPointIds()->SetNumberOfIds(n_points);
|
||||
|
||||
|
||||
for (int j = 1; j < n_points+1; ++j)
|
||||
polygon->GetPointIds()->SetId(j, look_up[polygons[j]]);
|
||||
|
||||
|
||||
vtkSmartPointer<vtkUnstructuredGrid> poly_grid = vtkSmartPointer<vtkUnstructuredGrid>::New();
|
||||
poly_grid->Allocate(1, 1);
|
||||
poly_grid->InsertNextCell(polygon->GetCellType(), polygon->GetPointIds());
|
||||
poly_grid->SetPoints(points);
|
||||
|
||||
|
||||
if (scalars)
|
||||
poly_grid->GetPointData()->SetScalars(scalars);
|
||||
|
||||
|
||||
data = poly_grid;
|
||||
}
|
||||
|
||||
@@ -750,7 +750,7 @@ cv::viz::WMesh::WMesh(const Mesh3d &mesh)
|
||||
actor->GetProperty()->SetInterpolationToFlat();
|
||||
actor->GetProperty()->EdgeVisibilityOff();
|
||||
actor->GetProperty()->ShadingOff();
|
||||
|
||||
|
||||
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New();
|
||||
#if VTK_MAJOR_VERSION <= 5
|
||||
mapper->SetInput(data);
|
||||
@@ -758,11 +758,11 @@ cv::viz::WMesh::WMesh(const Mesh3d &mesh)
|
||||
mapper->SetInputData(data);
|
||||
#endif
|
||||
mapper->ImmediateModeRenderingOff();
|
||||
|
||||
|
||||
vtkIdType numberOfCloudPoints = nr_points * 0.1;
|
||||
actor->SetNumberOfCloudPoints(int(numberOfCloudPoints > 1 ? numberOfCloudPoints : 1));
|
||||
actor->SetMapper(mapper);
|
||||
|
||||
|
||||
WidgetAccessor::setProp(*this, actor);
|
||||
}
|
||||
|
||||
|
||||
@@ -67,11 +67,11 @@ void cv::viz::InteractorStyle::Initialize()
|
||||
|
||||
init_ = true;
|
||||
stereo_anaglyph_mask_default_ = true;
|
||||
|
||||
|
||||
// Initialize the keyboard event callback as none
|
||||
keyboardCallback_ = 0;
|
||||
keyboard_callback_cookie_ = 0;
|
||||
|
||||
|
||||
// Initialize the mouse event callback as none
|
||||
mouseCallback_ = 0;
|
||||
mouse_callback_cookie_ = 0;
|
||||
@@ -197,7 +197,7 @@ void cv::viz::InteractorStyle::registerKeyboardCallback(void (*callback)(const K
|
||||
void
|
||||
cv::viz::InteractorStyle::OnKeyDown()
|
||||
{
|
||||
|
||||
|
||||
CV_Assert("Interactor style not initialized. Please call Initialize() before continuing" && init_);
|
||||
CV_Assert("No renderer given! Use SetRendererCollection() before continuing." && renderer_);
|
||||
|
||||
@@ -482,7 +482,7 @@ cv::viz::InteractorStyle::OnKeyDown()
|
||||
{
|
||||
if (it == widget_actor_map_->end())
|
||||
it = widget_actor_map_->begin();
|
||||
|
||||
|
||||
vtkProp3D * actor = vtkProp3D::SafeDownCast(it->second);
|
||||
if (actor && actor->GetUserMatrix())
|
||||
{
|
||||
@@ -554,7 +554,7 @@ void cv::viz::InteractorStyle::OnKeyUp()
|
||||
// Check if there is a keyboard callback registered
|
||||
if (keyboardCallback_)
|
||||
keyboardCallback_(event, keyboard_callback_cookie_);
|
||||
|
||||
|
||||
Superclass::OnKeyUp();
|
||||
}
|
||||
|
||||
@@ -673,10 +673,10 @@ void cv::viz::InteractorStyle::OnMouseWheelBackward()
|
||||
// If a mouse callback registered, call it!
|
||||
if (mouseCallback_)
|
||||
mouseCallback_(event, mouse_callback_cookie_);
|
||||
|
||||
|
||||
if (Interactor->GetRepeatCount() && mouseCallback_)
|
||||
mouseCallback_(event, mouse_callback_cookie_);
|
||||
|
||||
|
||||
if (Interactor->GetAltKey())
|
||||
{
|
||||
// zoom
|
||||
|
||||
@@ -85,7 +85,7 @@ namespace cv
|
||||
|
||||
/** \brief Change the default keyboard modified from ALT to a different special key.*/
|
||||
inline void setKeyboardModifier(const KeyboardModifier &modifier) { modifier_ = modifier; }
|
||||
|
||||
|
||||
protected:
|
||||
/** \brief Set to true after initialization is complete. */
|
||||
bool init_;
|
||||
@@ -95,7 +95,7 @@ namespace cv
|
||||
|
||||
/** \brief Actor map stored internally. */
|
||||
cv::Ptr<WidgetActorMap> widget_actor_map_;
|
||||
|
||||
|
||||
/** \brief The current window width/height. */
|
||||
Vec2i win_size_;
|
||||
|
||||
@@ -107,7 +107,7 @@ namespace cv
|
||||
|
||||
/** \brief A PNG writer for screenshot captures. */
|
||||
vtkSmartPointer<vtkPNGWriter> snapshot_writer_;
|
||||
|
||||
|
||||
/** \brief Internal window to image filter. Needed by \a snapshot_writer_. */
|
||||
vtkSmartPointer<vtkWindowToImageFilter> wif_;
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -120,10 +120,10 @@ struct cv::viz::Mesh3d::loadMeshImpl
|
||||
vtkSmartPointer<vtkPLYReader> reader = vtkSmartPointer<vtkPLYReader>::New();
|
||||
reader->SetFileName(file.c_str());
|
||||
reader->Update();
|
||||
|
||||
|
||||
vtkSmartPointer<vtkPolyData> poly_data = reader->GetOutput();
|
||||
CV_Assert("File does not exist or file format is not supported." && poly_data);
|
||||
|
||||
|
||||
vtkSmartPointer<vtkPoints> mesh_points = poly_data->GetPoints();
|
||||
vtkIdType nr_points = mesh_points->GetNumberOfPoints();
|
||||
|
||||
@@ -141,7 +141,7 @@ struct cv::viz::Mesh3d::loadMeshImpl
|
||||
vtkUnsignedCharArray* poly_colors = 0;
|
||||
if (poly_data->GetPointData())
|
||||
poly_colors = vtkUnsignedCharArray::SafeDownCast(poly_data->GetPointData()->GetScalars());
|
||||
|
||||
|
||||
if (poly_colors && (poly_colors->GetNumberOfComponents() == 3))
|
||||
{
|
||||
mesh.colors.create(1, nr_points, CV_8UC3);
|
||||
@@ -164,9 +164,9 @@ struct cv::viz::Mesh3d::loadMeshImpl
|
||||
vtkIdType nr_cell_points;
|
||||
vtkCellArray * mesh_polygons = poly_data->GetPolys();
|
||||
mesh_polygons->InitTraversal();
|
||||
|
||||
|
||||
mesh.polygons.create(1, mesh_polygons->GetSize(), CV_32SC1);
|
||||
|
||||
|
||||
int* polygons = mesh.polygons.ptr<int>();
|
||||
while (mesh_polygons->GetNextCell(nr_cell_points, cell_points))
|
||||
{
|
||||
@@ -213,30 +213,30 @@ cv::viz::Camera::Camera(const cv::Matx33f & K, const Size &window_size)
|
||||
}
|
||||
|
||||
cv::viz::Camera::Camera(const Matx44f &proj, const Size &window_size)
|
||||
{
|
||||
{
|
||||
CV_Assert(window_size.width > 0 && window_size.height > 0);
|
||||
|
||||
|
||||
double near = proj(2,3) / (proj(2,2) - 1.0);
|
||||
double far = near * (proj(2,2) - 1.0) / (proj(2,2) + 1.0);
|
||||
double left = near * (proj(0,2)-1) / proj(0,0);
|
||||
double right = 2.0 * near / proj(0,0) + left;
|
||||
double bottom = near * (proj(1,2)-1) / proj(1,1);
|
||||
double top = 2.0 * near / proj(1,1) + bottom;
|
||||
|
||||
|
||||
double epsilon = 2.2204460492503131e-16;
|
||||
|
||||
|
||||
if (fabs(left-right) < epsilon) principal_point_[0] = static_cast<float>(window_size.width) * 0.5f;
|
||||
else principal_point_[0] = (left * static_cast<float>(window_size.width)) / (left - right);
|
||||
else principal_point_[0] = (left * static_cast<float>(window_size.width)) / (left - right);
|
||||
focal_[0] = -near * principal_point_[0] / left;
|
||||
|
||||
if (fabs(top-bottom) < epsilon) principal_point_[1] = static_cast<float>(window_size.height) * 0.5f;
|
||||
else principal_point_[1] = (top * static_cast<float>(window_size.height)) / (top - bottom);
|
||||
|
||||
if (fabs(top-bottom) < epsilon) principal_point_[1] = static_cast<float>(window_size.height) * 0.5f;
|
||||
else principal_point_[1] = (top * static_cast<float>(window_size.height)) / (top - bottom);
|
||||
focal_[1] = near * principal_point_[1] / top;
|
||||
|
||||
|
||||
setClip(Vec2d(near, far));
|
||||
fov_[0] = (atan2(principal_point_[0],focal_[0]) + atan2(window_size.width-principal_point_[0],focal_[0]));
|
||||
fov_[1] = (atan2(principal_point_[1],focal_[1]) + atan2(window_size.height-principal_point_[1],focal_[1]));
|
||||
|
||||
|
||||
window_size_ = window_size;
|
||||
}
|
||||
|
||||
@@ -244,33 +244,33 @@ void cv::viz::Camera::init(float f_x, float f_y, float c_x, float c_y, const Siz
|
||||
{
|
||||
CV_Assert(window_size.width > 0 && window_size.height > 0);
|
||||
setClip(Vec2d(0.01, 1000.01));// Default clipping
|
||||
|
||||
|
||||
fov_[0] = (atan2(c_x,f_x) + atan2(window_size.width-c_x,f_x));
|
||||
fov_[1] = (atan2(c_y,f_y) + atan2(window_size.height-c_y,f_y));
|
||||
|
||||
|
||||
principal_point_[0] = c_x;
|
||||
principal_point_[1] = c_y;
|
||||
|
||||
|
||||
focal_[0] = f_x;
|
||||
focal_[1] = f_y;
|
||||
|
||||
|
||||
window_size_ = window_size;
|
||||
}
|
||||
|
||||
void cv::viz::Camera::setWindowSize(const Size &window_size)
|
||||
{
|
||||
CV_Assert(window_size.width > 0 && window_size.height > 0);
|
||||
|
||||
|
||||
// Get the scale factor and update the principal points
|
||||
float scalex = static_cast<float>(window_size.width) / static_cast<float>(window_size_.width);
|
||||
float scaley = static_cast<float>(window_size.height) / static_cast<float>(window_size_.height);
|
||||
|
||||
|
||||
principal_point_[0] *= scalex;
|
||||
principal_point_[1] *= scaley;
|
||||
focal_ *= scaley;
|
||||
// Vertical field of view is fixed! Update horizontal field of view
|
||||
fov_[0] = (atan2(principal_point_[0],focal_[0]) + atan2(window_size.width-principal_point_[0],focal_[0]));
|
||||
|
||||
|
||||
window_size_ = window_size;
|
||||
}
|
||||
|
||||
@@ -280,12 +280,12 @@ void cv::viz::Camera::computeProjectionMatrix(Matx44f &proj) const
|
||||
double left = -clip_[0] * principal_point_[0] / focal_[0];
|
||||
double right = clip_[0] * (window_size_.width - principal_point_[0]) / focal_[0];
|
||||
double bottom = -clip_[0] * (window_size_.height - principal_point_[1]) / focal_[1];
|
||||
|
||||
|
||||
double temp1 = 2.0 * clip_[0];
|
||||
double temp2 = 1.0 / (right - left);
|
||||
double temp3 = 1.0 / (top - bottom);
|
||||
double temp4 = 1.0 / (clip_[0] - clip_[1]);
|
||||
|
||||
|
||||
proj = Matx44d::zeros();
|
||||
proj(0,0) = temp1 * temp2;
|
||||
proj(1,1) = temp1 * temp3;
|
||||
@@ -300,7 +300,7 @@ cv::viz::Camera cv::viz::Camera::KinectCamera(const Size &window_size)
|
||||
{
|
||||
// Without distortion, RGB Camera
|
||||
// Received from http://nicolas.burrus.name/index.php/Research/KinectCalibration
|
||||
Matx33f K = Matx33f::zeros();
|
||||
Matx33f K = Matx33f::zeros();
|
||||
K(0,0) = 5.2921508098293293e+02;
|
||||
K(0,2) = 3.2894272028759258e+02;
|
||||
K(1,1) = 5.2556393630057437e+02;
|
||||
|
||||
@@ -72,7 +72,7 @@ cv::Affine3f cv::viz::makeCameraPose(const Vec3f& position, const Vec3f& focal_p
|
||||
Vec3f n = normalize(focal_point - position);
|
||||
Vec3f u = normalize(y_dir.cross(n));
|
||||
Vec3f v = n.cross(u);
|
||||
|
||||
|
||||
Matx44f pose_mat = Matx44f::zeros();
|
||||
pose_mat(0,0) = u[0];
|
||||
pose_mat(0,1) = u[1];
|
||||
@@ -147,9 +147,9 @@ struct cv::viz::VizAccessor::VizAccessorImpl
|
||||
|
||||
cv::viz::VizAccessor::VizAccessor() { impl_ = new cv::viz::VizAccessor::VizAccessorImpl;}
|
||||
|
||||
cv::viz::VizAccessor::~VizAccessor()
|
||||
{
|
||||
if(impl_)
|
||||
cv::viz::VizAccessor::~VizAccessor()
|
||||
{
|
||||
if(impl_)
|
||||
{
|
||||
delete impl_;
|
||||
impl_ = 0;
|
||||
@@ -202,7 +202,7 @@ void cv::viz::VizAccessor::remove(const String &window_name)
|
||||
// Add the prefix Viz
|
||||
String name;
|
||||
generateWindowName(window_name, name);
|
||||
|
||||
|
||||
VizMap::iterator vm_itr = impl_->viz_map.find(name);
|
||||
bool exists = vm_itr != impl_->viz_map.end();
|
||||
if (!exists) return ;
|
||||
@@ -214,7 +214,7 @@ void cv::viz::VizAccessor::generateWindowName(const String &window_name, String
|
||||
output = "Viz";
|
||||
// Already is Viz
|
||||
if (window_name == output) return;
|
||||
|
||||
|
||||
String prefixed = output + " - ";
|
||||
if (window_name.substr(0, prefixed.length()) == prefixed) output = window_name; // Already has "Viz - "
|
||||
else if (window_name.substr(0, output.length()) == output) output = prefixed + window_name; // Doesn't have prefix
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
|
||||
cv::viz::Viz3d::Viz3d(const String& window_name) : impl_(0) { create(window_name); }
|
||||
|
||||
cv::viz::Viz3d::Viz3d(const Viz3d& other) : impl_(other.impl_)
|
||||
cv::viz::Viz3d::Viz3d(const Viz3d& other) : impl_(other.impl_)
|
||||
{
|
||||
if (impl_) CV_XADD(&impl_->ref_counter, 1);
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ cv::viz::Viz3d::VizImpl::VizImpl(const String &name)
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
cv::viz::Viz3d::VizImpl::~VizImpl()
|
||||
{
|
||||
if (interactor_)
|
||||
if (interactor_)
|
||||
interactor_->DestroyTimer(timer_id_);
|
||||
if (renderer_) renderer_->Clear();
|
||||
}
|
||||
@@ -368,11 +368,11 @@ void cv::viz::Viz3d::VizImpl::setBackgroundColor(const Color& color)
|
||||
void cv::viz::Viz3d::VizImpl::setCamera(const Camera &camera)
|
||||
{
|
||||
vtkCamera& active_camera = *renderer_->GetActiveCamera();
|
||||
|
||||
|
||||
// Set the intrinsic parameters of the camera
|
||||
window_->SetSize(camera.getWindowSize().width, camera.getWindowSize().height);
|
||||
double aspect_ratio = static_cast<double>(camera.getWindowSize().width)/static_cast<double>(camera.getWindowSize().height);
|
||||
|
||||
|
||||
Matx44f proj_mat;
|
||||
camera.computeProjectionMatrix(proj_mat);
|
||||
// Use the intrinsic parameters of the camera to simulate more realistically
|
||||
@@ -382,7 +382,7 @@ void cv::viz::Viz3d::VizImpl::setCamera(const Camera &camera)
|
||||
transform->SetMatrix(convertToVtkMatrix(proj_mat * old_proj_mat.inv()));
|
||||
active_camera.SetUserTransform(transform);
|
||||
transform->Delete();
|
||||
|
||||
|
||||
renderer_->ResetCameraClippingRange();
|
||||
renderer_->Render();
|
||||
}
|
||||
@@ -391,11 +391,11 @@ void cv::viz::Viz3d::VizImpl::setCamera(const Camera &camera)
|
||||
cv::viz::Camera cv::viz::Viz3d::VizImpl::getCamera() const
|
||||
{
|
||||
vtkCamera& active_camera = *renderer_->GetActiveCamera();
|
||||
|
||||
|
||||
Size window_size(renderer_->GetRenderWindow()->GetSize()[0],
|
||||
renderer_->GetRenderWindow()->GetSize()[1]);
|
||||
double aspect_ratio = static_cast<double>(window_size.width) / static_cast<double>(window_size.height);
|
||||
|
||||
|
||||
Matx44f proj_matrix = convertToMatx(active_camera.GetProjectionTransformMatrix(aspect_ratio, -1.0f, 1.0f));
|
||||
Camera camera(proj_matrix, window_size);
|
||||
return camera;
|
||||
@@ -405,7 +405,7 @@ cv::viz::Camera cv::viz::Viz3d::VizImpl::getCamera() const
|
||||
void cv::viz::Viz3d::VizImpl::setViewerPose(const Affine3f &pose)
|
||||
{
|
||||
vtkCamera& camera = *renderer_->GetActiveCamera();
|
||||
|
||||
|
||||
// Position = extrinsic translation
|
||||
cv::Vec3f pos_vec = pose.translation();
|
||||
|
||||
@@ -417,11 +417,11 @@ void cv::viz::Viz3d::VizImpl::setViewerPose(const Affine3f &pose)
|
||||
// Compute the new focal point
|
||||
cv::Vec3f z_axis(0.f, 0.f, 1.f);
|
||||
cv::Vec3f focal_vec = pos_vec + rotation * z_axis;
|
||||
|
||||
|
||||
camera.SetPosition(pos_vec[0], pos_vec[1], pos_vec[2]);
|
||||
camera.SetFocalPoint(focal_vec[0], focal_vec[1], focal_vec[2]);
|
||||
camera.SetViewUp(up_vec[0], up_vec[1], up_vec[2]);
|
||||
|
||||
|
||||
renderer_->ResetCameraClippingRange();
|
||||
renderer_->Render();
|
||||
}
|
||||
@@ -465,10 +465,10 @@ void cv::viz::Viz3d::VizImpl::convertToWindowCoordinates(const Point3d &pt, Poin
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void cv::viz::Viz3d::VizImpl::converTo3DRay(const Point3d &window_coord, Point3d &origin, Vec3d &direction)
|
||||
{
|
||||
{
|
||||
Vec4d world_pt;
|
||||
vtkInteractorObserver::ComputeDisplayToWorld(renderer_, window_coord.x, window_coord.y, window_coord.z, world_pt.val);
|
||||
|
||||
|
||||
vtkCamera &active_camera = *renderer_->GetActiveCamera();
|
||||
Vec3d cam_pos;
|
||||
active_camera.GetPosition(cam_pos.val);
|
||||
@@ -525,19 +525,19 @@ void cv::viz::Viz3d::VizImpl::setRepresentation(int representation)
|
||||
vtkActor * actor;
|
||||
switch (representation)
|
||||
{
|
||||
case REPRESENTATION_POINTS:
|
||||
case REPRESENTATION_POINTS:
|
||||
{
|
||||
while ((actor = actors->GetNextActor()) != NULL)
|
||||
actor->GetProperty()->SetRepresentationToPoints();
|
||||
break;
|
||||
}
|
||||
case REPRESENTATION_SURFACE:
|
||||
case REPRESENTATION_SURFACE:
|
||||
{
|
||||
while ((actor = actors->GetNextActor()) != NULL)
|
||||
actor->GetProperty()->SetRepresentationToSurface();
|
||||
break;
|
||||
}
|
||||
case REPRESENTATION_WIREFRAME:
|
||||
case REPRESENTATION_WIREFRAME:
|
||||
{
|
||||
while ((actor = actors->GetNextActor()) != NULL)
|
||||
actor->GetProperty()->SetRepresentationToWireframe();
|
||||
|
||||
@@ -58,20 +58,20 @@ public:
|
||||
typedef cv::Ptr<VizImpl> Ptr;
|
||||
typedef Viz3d::KeyboardCallback KeyboardCallback;
|
||||
typedef Viz3d::MouseCallback MouseCallback;
|
||||
|
||||
|
||||
int ref_counter;
|
||||
|
||||
VizImpl(const String &name);
|
||||
virtual ~VizImpl();
|
||||
|
||||
|
||||
void showWidget(const String &id, const Widget &widget, const Affine3f &pose = Affine3f::Identity());
|
||||
void removeWidget(const String &id);
|
||||
Widget getWidget(const String &id) const;
|
||||
void removeAllWidgets();
|
||||
|
||||
|
||||
void setWidgetPose(const String &id, const Affine3f &pose);
|
||||
void updateWidgetPose(const String &id, const Affine3f &pose);
|
||||
Affine3f getWidgetPose(const String &id) const;
|
||||
Affine3f getWidgetPose(const String &id) const;
|
||||
|
||||
void setDesiredUpdateRate(double rate);
|
||||
double getDesiredUpdateRate();
|
||||
@@ -86,7 +86,7 @@ public:
|
||||
void close()
|
||||
{
|
||||
stopped_ = true;
|
||||
if (interactor_)
|
||||
if (interactor_)
|
||||
{
|
||||
interactor_->GetRenderWindow()->Finalize();
|
||||
interactor_->TerminateApp(); // This tends to close the window...
|
||||
@@ -94,14 +94,14 @@ public:
|
||||
}
|
||||
|
||||
void setRepresentation(int representation);
|
||||
|
||||
|
||||
void setCamera(const Camera &camera);
|
||||
Camera getCamera() const;
|
||||
|
||||
/** \brief Reset the camera to a given widget */
|
||||
void resetCameraViewpoint(const String& id);
|
||||
void resetCamera();
|
||||
|
||||
|
||||
void setViewerPose(const Affine3f &pose);
|
||||
Affine3f getViewerPose();
|
||||
|
||||
@@ -182,7 +182,7 @@ private:
|
||||
|
||||
/** \brief The render window interactor style. */
|
||||
vtkSmartPointer<InteractorStyle> style_;
|
||||
|
||||
|
||||
/** \brief Internal list with actor pointers and name IDs for all widget actors */
|
||||
cv::Ptr<WidgetActorMap> widget_actor_map_;
|
||||
|
||||
@@ -245,7 +245,7 @@ namespace cv
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
static _Out* copyColor(const Mat& source, _Out* output, const Mat& nan_mask)
|
||||
{
|
||||
CV_Assert(DataDepth<_Tp>::value == source.depth() && source.size() == nan_mask.size());
|
||||
@@ -282,7 +282,7 @@ namespace cv
|
||||
|
||||
return table[nan_mask.depth() - 5](source, output, nan_mask);
|
||||
}
|
||||
|
||||
|
||||
template<typename _Tp>
|
||||
static inline Vec<_Tp, 3>* copyColor(const Mat& source, Vec<_Tp, 3>* output, const Mat& nan_mask)
|
||||
{
|
||||
@@ -328,7 +328,7 @@ namespace cv
|
||||
|
||||
inline Vec3d vtkpoint(const Point3f& point) { return Vec3d(point.x, point.y, point.z); }
|
||||
template<typename _Tp> inline _Tp normalized(const _Tp& v) { return v * 1/cv::norm(v); }
|
||||
|
||||
|
||||
struct ConvertToVtkImage
|
||||
{
|
||||
struct Impl
|
||||
@@ -336,7 +336,7 @@ namespace cv
|
||||
static void copyImageMultiChannel(const Mat &image, vtkSmartPointer<vtkImageData> output)
|
||||
{
|
||||
int i_chs = image.channels();
|
||||
|
||||
|
||||
for (int i = 0; i < image.rows; ++i)
|
||||
{
|
||||
const unsigned char * irows = image.ptr<unsigned char>(i);
|
||||
@@ -349,7 +349,7 @@ namespace cv
|
||||
}
|
||||
output->Modified();
|
||||
}
|
||||
|
||||
|
||||
static void copyImageSingleChannel(const Mat &image, vtkSmartPointer<vtkImageData> output)
|
||||
{
|
||||
for (int i = 0; i < image.rows; ++i)
|
||||
@@ -364,7 +364,7 @@ namespace cv
|
||||
output->Modified();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
static void convert(const Mat &image, vtkSmartPointer<vtkImageData> output)
|
||||
{
|
||||
// Create the vtk image
|
||||
@@ -376,7 +376,7 @@ namespace cv
|
||||
#else
|
||||
output->AllocateScalars(VTK_UNSIGNED_CHAR, image.channels());
|
||||
#endif
|
||||
|
||||
|
||||
int i_chs = image.channels();
|
||||
if (i_chs > 1)
|
||||
{
|
||||
|
||||
@@ -55,14 +55,14 @@ class cv::viz::Widget::Impl
|
||||
{
|
||||
public:
|
||||
vtkSmartPointer<vtkProp> prop;
|
||||
|
||||
|
||||
Impl() : prop(0) {}
|
||||
};
|
||||
|
||||
cv::viz::Widget::Widget() : impl_( new Impl() ) { }
|
||||
|
||||
cv::viz::Widget::Widget(const Widget& other) : impl_( new Impl() )
|
||||
{
|
||||
{
|
||||
if (other.impl_ && other.impl_->prop) impl_->prop = other.impl_->prop;
|
||||
}
|
||||
|
||||
@@ -73,8 +73,8 @@ cv::viz::Widget& cv::viz::Widget::operator=(const Widget& other)
|
||||
return *this;
|
||||
}
|
||||
|
||||
cv::viz::Widget::~Widget()
|
||||
{
|
||||
cv::viz::Widget::~Widget()
|
||||
{
|
||||
if (impl_)
|
||||
{
|
||||
delete impl_;
|
||||
@@ -86,7 +86,7 @@ cv::viz::Widget cv::viz::Widget::fromPlyFile(const String &file_name)
|
||||
{
|
||||
vtkSmartPointer<vtkPLYReader> reader = vtkSmartPointer<vtkPLYReader>::New();
|
||||
reader->SetFileName(file_name.c_str());
|
||||
|
||||
|
||||
vtkSmartPointer<vtkDataSet> data = reader->GetOutput();
|
||||
CV_Assert("File does not exist or file format is not supported." && data);
|
||||
|
||||
@@ -120,7 +120,7 @@ cv::viz::Widget cv::viz::Widget::fromPlyFile(const String &file_name)
|
||||
actor->GetProperty()->BackfaceCullingOn();
|
||||
|
||||
actor->SetMapper(mapper);
|
||||
|
||||
|
||||
Widget widget;
|
||||
widget.impl_->prop = actor;
|
||||
return widget;
|
||||
@@ -130,7 +130,7 @@ void cv::viz::Widget::setRenderingProperty(int property, double value)
|
||||
{
|
||||
vtkActor *actor = vtkActor::SafeDownCast(WidgetAccessor::getProp(*this));
|
||||
CV_Assert("Widget type is not supported." && actor);
|
||||
|
||||
|
||||
switch (property)
|
||||
{
|
||||
case POINT_SIZE:
|
||||
@@ -218,8 +218,8 @@ void cv::viz::Widget::setRenderingProperty(int property, double value)
|
||||
actor->Modified();
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
default:
|
||||
CV_Assert("setPointCloudRenderingProperties: Unknown property");
|
||||
}
|
||||
@@ -229,7 +229,7 @@ double cv::viz::Widget::getRenderingProperty(int property) const
|
||||
{
|
||||
vtkActor *actor = vtkActor::SafeDownCast(WidgetAccessor::getProp(*this));
|
||||
CV_Assert("Widget type is not supported." && actor);
|
||||
|
||||
|
||||
double value = 0.0;
|
||||
switch (property)
|
||||
{
|
||||
@@ -313,7 +313,7 @@ struct cv::viz::Widget3D::MatrixConverter
|
||||
m(i, k) = vtk_matrix->GetElement(i, k);
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
static vtkSmartPointer<vtkMatrix4x4> convertToVtkMatrix(const Matx44f& m)
|
||||
{
|
||||
vtkSmartPointer<vtkMatrix4x4> vtk_matrix = vtkSmartPointer<vtkMatrix4x4>::New();
|
||||
@@ -328,7 +328,7 @@ void cv::viz::Widget3D::setPose(const Affine3f &pose)
|
||||
{
|
||||
vtkProp3D *actor = vtkProp3D::SafeDownCast(WidgetAccessor::getProp(*this));
|
||||
CV_Assert("Widget is not 3D." && actor);
|
||||
|
||||
|
||||
vtkSmartPointer<vtkMatrix4x4> matrix = convertToVtkMatrix(pose.matrix);
|
||||
actor->SetUserMatrix(matrix);
|
||||
actor->Modified();
|
||||
@@ -338,7 +338,7 @@ void cv::viz::Widget3D::updatePose(const Affine3f &pose)
|
||||
{
|
||||
vtkProp3D *actor = vtkProp3D::SafeDownCast(WidgetAccessor::getProp(*this));
|
||||
CV_Assert("Widget is not 3D." && actor);
|
||||
|
||||
|
||||
vtkSmartPointer<vtkMatrix4x4> matrix = actor->GetUserMatrix();
|
||||
if (!matrix)
|
||||
{
|
||||
@@ -358,7 +358,7 @@ cv::Affine3f cv::viz::Widget3D::getPose() const
|
||||
{
|
||||
vtkProp3D *actor = vtkProp3D::SafeDownCast(WidgetAccessor::getProp(*this));
|
||||
CV_Assert("Widget is not 3D." && actor);
|
||||
|
||||
|
||||
vtkSmartPointer<vtkMatrix4x4> matrix = actor->GetUserMatrix();
|
||||
Matx44f matrix_cv = MatrixConverter::convertToMatx(matrix);
|
||||
return Affine3f(matrix_cv);
|
||||
@@ -369,7 +369,7 @@ void cv::viz::Widget3D::setColor(const Color &color)
|
||||
// Cast to actor instead of prop3d since prop3d doesn't provide getproperty
|
||||
vtkActor *actor = vtkActor::SafeDownCast(WidgetAccessor::getProp(*this));
|
||||
CV_Assert("Widget type is not supported." && actor);
|
||||
|
||||
|
||||
Color c = vtkcolor(color);
|
||||
actor->GetMapper()->ScalarVisibilityOff();
|
||||
actor->GetProperty()->SetColor(c.val);
|
||||
|
||||
Reference in New Issue
Block a user