1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-31 08:13:04 +04:00

added test for trajectories and fixed bug with float type

This commit is contained in:
Anatoly Baksheev
2014-01-08 19:43:20 +04:00
parent 64566e6178
commit 25b417e8b2
9 changed files with 128 additions and 105 deletions
+16
View File
@@ -221,6 +221,22 @@ namespace cv
return scalars;
}
};
inline vtkSmartPointer<vtkMatrix4x4> vtkmatrix(const cv::Matx44d &matrix)
{
vtkSmartPointer<vtkMatrix4x4> vtk_matrix = vtkSmartPointer<vtkMatrix4x4>::New();
vtk_matrix->DeepCopy(matrix.val);
return vtk_matrix;
}
inline Color vtkcolor(const Color& color)
{
Color scaled_color = color * (1.0/255.0);
std::swap(scaled_color[0], scaled_color[2]);
return scaled_color;
}
template<typename _Tp> inline _Tp normalized(const _Tp& v) { return v * 1/norm(v); }
}
}
+39 -40
View File
@@ -70,6 +70,35 @@ template<> cv::viz::WLine cv::viz::Widget::cast<cv::viz::WLine>()
return static_cast<WLine&>(widget);
}
///////////////////////////////////////////////////////////////////////////////////////////////
/// sphere widget implementation
cv::viz::WSphere::WSphere(const Point3d &center, double radius, int sphere_resolution, const Color &color)
{
vtkSmartPointer<vtkSphereSource> sphere = vtkSmartPointer<vtkSphereSource>::New();
sphere->SetRadius(radius);
sphere->SetCenter(center.x, center.y, center.z);
sphere->SetPhiResolution(sphere_resolution);
sphere->SetThetaResolution(sphere_resolution);
sphere->LatLongTessellationOff();
sphere->Update();
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
VtkUtils::SetInputData(mapper, sphere->GetOutput());
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
WidgetAccessor::setProp(*this, actor);
setColor(color);
}
template<> cv::viz::WSphere cv::viz::Widget::cast<cv::viz::WSphere>()
{
Widget3D widget = this->cast<Widget3D>();
return static_cast<WSphere&>(widget);
}
///////////////////////////////////////////////////////////////////////////////////////////////
/// plane widget implementation
@@ -143,51 +172,21 @@ template<> cv::viz::WPlane cv::viz::Widget::cast<cv::viz::WPlane>()
return static_cast<WPlane&>(widget);
}
///////////////////////////////////////////////////////////////////////////////////////////////
/// sphere widget implementation
cv::viz::WSphere::WSphere(const Point3d &center, double radius, int sphere_resolution, const Color &color)
{
vtkSmartPointer<vtkSphereSource> sphere = vtkSmartPointer<vtkSphereSource>::New();
sphere->SetRadius(radius);
sphere->SetCenter(center.x, center.y, center.z);
sphere->SetPhiResolution(sphere_resolution);
sphere->SetThetaResolution(sphere_resolution);
sphere->LatLongTessellationOff();
sphere->Update();
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
VtkUtils::SetInputData(mapper, sphere->GetOutput());
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
WidgetAccessor::setProp(*this, actor);
setColor(color);
}
template<> cv::viz::WSphere cv::viz::Widget::cast<cv::viz::WSphere>()
{
Widget3D widget = this->cast<Widget3D>();
return static_cast<WSphere&>(widget);
}
///////////////////////////////////////////////////////////////////////////////////////////////
/// arrow widget implementation
cv::viz::WArrow::WArrow(const Point3d& pt1, const Point3d& pt2, double thickness, const Color &color)
{
vtkSmartPointer<vtkArrowSource> arrowSource = vtkSmartPointer<vtkArrowSource>::New();
arrowSource->SetShaftRadius(thickness);
// The thickness and radius of the tip are adjusted based on the thickness of the arrow
arrowSource->SetTipRadius(thickness * 3.0);
arrowSource->SetTipLength(thickness * 10.0);
vtkSmartPointer<vtkArrowSource> arrow_source = vtkSmartPointer<vtkArrowSource>::New();
arrow_source->SetShaftRadius(thickness);
arrow_source->SetTipRadius(thickness * 3.0);
arrow_source->SetTipLength(thickness * 10.0);
RNG rng = theRNG();
Vec3d arbitrary(rng.uniform(-10.0, 10.0), rng.uniform(-10.0, 10.0), rng.uniform(-10.0, 10.0));
Vec3d startPoint(pt1.x, pt1.y, pt1.z), endPoint(pt2.x, pt2.y, pt2.z);
double length = cv::norm(endPoint - startPoint);
double length = norm(endPoint - startPoint);
Vec3d xvec = normalized(endPoint - startPoint);
Vec3d zvec = normalized(xvec.cross(arbitrary));
@@ -204,7 +203,7 @@ cv::viz::WArrow::WArrow(const Point3d& pt1, const Point3d& pt2, double thickness
// Transform the polydata
vtkSmartPointer<vtkTransformPolyDataFilter> transformPD = vtkSmartPointer<vtkTransformPolyDataFilter>::New();
transformPD->SetTransform(transform);
transformPD->SetInputConnection(arrowSource->GetOutputPort());
transformPD->SetInputConnection(arrow_source->GetOutputPort());
transformPD->Update();
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
@@ -908,14 +907,14 @@ namespace cv { namespace viz { namespace
actor->SetTexture(texture);
}
static vtkSmartPointer<vtkPolyData> createFrustrum(double aspect_ratio, double fovy, double scale)
static vtkSmartPointer<vtkPolyData> createFrustum(double aspect_ratio, double fovy, double scale)
{
vtkSmartPointer<vtkCamera> camera = vtkSmartPointer<vtkCamera>::New();
camera->SetViewAngle(fovy);
camera->SetPosition(0.0, 0.0, 0.0);
camera->SetViewUp(0.0, 1.0, 0.0);
camera->SetFocalPoint(0.0, 0.0, 1.0);
camera->SetClippingRange(0.01, scale);
camera->SetClippingRange(1e-9, scale);
double planesArray[24];
camera->GetFrustumPlanes(aspect_ratio, planesArray);
@@ -956,7 +955,7 @@ cv::viz::WCameraPosition::WCameraPosition(const Matx33d &K, double scale, const
double fovy = 2.0 * atan2(c_y, f_y) * 180 / CV_PI;
double aspect_ratio = f_y / f_x;
vtkSmartPointer<vtkPolyData> polydata = CameraPositionUtils::createFrustrum(aspect_ratio, fovy, scale);
vtkSmartPointer<vtkPolyData> polydata = CameraPositionUtils::createFrustum(aspect_ratio, fovy, scale);
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
VtkUtils::SetInputData(mapper, polydata);
@@ -973,7 +972,7 @@ cv::viz::WCameraPosition::WCameraPosition(const Vec2d &fov, double scale, const
double aspect_ratio = tan(fov[0] * 0.5) / tan(fov[1] * 0.5);
double fovy = fov[1] * 180 / CV_PI;
vtkSmartPointer<vtkPolyData> polydata = CameraPositionUtils::createFrustrum(aspect_ratio, fovy, scale);
vtkSmartPointer<vtkPolyData> polydata = CameraPositionUtils::createFrustum(aspect_ratio, fovy, scale);
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
VtkUtils::SetInputData(mapper, polydata);
-18
View File
@@ -179,34 +179,16 @@ private:
bool removeActorFromRenderer(const vtkSmartPointer<vtkProp> &actor);
};
namespace cv
{
namespace viz
{
inline vtkSmartPointer<vtkMatrix4x4> vtkmatrix(const cv::Matx44d &matrix)
{
vtkSmartPointer<vtkMatrix4x4> vtk_matrix = vtkSmartPointer<vtkMatrix4x4>::New();
vtk_matrix->DeepCopy(matrix.val);
return vtk_matrix;
}
struct color_tag {};
struct gray_tag {};
inline Vec3b fetchRgb(const unsigned char* color, color_tag) { return Vec3b(color[2], color[1], color[0]); }
inline Vec3b fetchRgb(const unsigned char* color, gray_tag) { return Vec3b(color[0], color[0], color[0]); }
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); }
inline Color vtkcolor(const Color& color)
{
Color scaled_color = color * (1.0/255.0);
std::swap(scaled_color[0], scaled_color[2]);
return scaled_color;
}
struct ConvertToVtkImage
{
struct Impl
+2 -4
View File
@@ -59,9 +59,8 @@ void cv::viz::vtkTrajectorySource::SetTrajectory(InputArray _traj)
Mat traj;
_traj.getMat().convertTo(traj, CV_64F);
const Affine3d* dpath = _traj.getMat().ptr<Affine3d>();
size_t total = _traj.total();
const Affine3d* dpath = traj.ptr<Affine3d>();
size_t total = traj.total();
points = vtkSmartPointer<vtkPoints>::New();
points->SetDataType(VTK_DOUBLE);
@@ -81,7 +80,6 @@ void cv::viz::vtkTrajectorySource::SetTrajectory(InputArray _traj)
}
}
cv::Mat cv::viz::vtkTrajectorySource::ExtractPoints(InputArray _traj)
{
CV_Assert(_traj.kind() == _InputArray::STD_VECTOR || _traj.kind() == _InputArray::MAT);
+6 -12
View File
@@ -140,14 +140,11 @@ void cv::viz::Widget::setRenderingProperty(int property, double value)
{
if (!actor->GetMapper()->GetInput()->GetPointData()->GetNormals())
{
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkPolyDataMapper::SafeDownCast(actor->GetMapper());
vtkSmartPointer<vtkPolyDataNormals> normals = vtkSmartPointer<vtkPolyDataNormals>::New();
#if VTK_MAJOR_VERSION <= 5
normals->SetInput(actor->GetMapper()->GetInput());
#else
normals->SetInputData(actor->GetMapper()->GetInput());
#endif
VtkUtils::SetInputData(normals, mapper->GetInput());
normals->Update();
vtkDataSetMapper::SafeDownCast(actor->GetMapper())->SetInputConnection(normals->GetOutputPort());
VtkUtils::SetInputData(mapper, normals->GetOutput());
}
actor->GetProperty()->SetInterpolationToGouraud();
break;
@@ -156,14 +153,11 @@ void cv::viz::Widget::setRenderingProperty(int property, double value)
{
if (!actor->GetMapper()->GetInput()->GetPointData()->GetNormals())
{
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkPolyDataMapper::SafeDownCast(actor->GetMapper());
vtkSmartPointer<vtkPolyDataNormals> normals = vtkSmartPointer<vtkPolyDataNormals>::New();
#if VTK_MAJOR_VERSION <= 5
normals->SetInput(actor->GetMapper()->GetInput());
#else
normals->SetInputData(actor->GetMapper()->GetInput());
#endif
VtkUtils::SetInputData(normals, mapper->GetInput());
normals->Update();
vtkDataSetMapper::SafeDownCast(actor->GetMapper())->SetInputConnection(normals->GetOutputPort());
VtkUtils::SetInputData(mapper, normals->GetOutput());
}
actor->GetProperty()->SetInterpolationToPhong();
break;