From: Anatoly Baksheev Date: Tue, 7 Jan 2014 17:13:15 +0000 (+0400) Subject: more refactoring X-Git-Tag: submit/tizen_ivi/20141117.190038~2^2~714^2~49 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d26446542248d4d3442a761a46bcd77e36a8e45c;p=profile%2Fivi%2Fopencv.git more refactoring --- diff --git a/modules/viz/include/opencv2/viz/widgets.hpp b/modules/viz/include/opencv2/viz/widgets.hpp index 2868880..b487952 100644 --- a/modules/viz/include/opencv2/viz/widgets.hpp +++ b/modules/viz/include/opencv2/viz/widgets.hpp @@ -227,7 +227,7 @@ namespace cv class CV_EXPORTS WCoordinateSystem : public Widget3D { public: - WCoordinateSystem(float scale = 1.f); + WCoordinateSystem(double scale = 1.f); }; class CV_EXPORTS WGrid : public Widget3D @@ -263,7 +263,7 @@ namespace cv enum {FRAMES = 1, PATH = 2, BOTH = FRAMES + PATH }; //! Takes vector> and displays trajectory of the given path either by coordinate frames or polyline - WTrajectory(InputArray path, int display_mode = WTrajectory::PATH, float scale = 1.f, const Color &color = Color::white()); + WTrajectory(InputArray path, int display_mode = WTrajectory::PATH, double scale = 1.f, const Color &color = Color::white()); }; class CV_EXPORTS WTrajectoryFrustums : public Widget3D diff --git a/modules/viz/src/precomp.hpp b/modules/viz/src/precomp.hpp index 85977a8..b91e50c 100644 --- a/modules/viz/src/precomp.hpp +++ b/modules/viz/src/precomp.hpp @@ -172,10 +172,40 @@ namespace cv friend class Viz3d; }; - template bool isNan(const _Tp* data) + template inline bool isNan(const _Tp* data) { return isNan(data[0]) || isNan(data[1]) || isNan(data[2]); } + + inline vtkSmartPointer getPolyData(const Widget3D& widget) + { + vtkSmartPointer prop = WidgetAccessor::getProp(widget); + vtkSmartPointer mapper = vtkActor::SafeDownCast(prop)->GetMapper(); + return vtkPolyData::SafeDownCast(mapper->GetInput()); + } + + struct VtkUtils + { + template + static inline void SetInputData(vtkSmartPointer filter, vtkPolyData *polydata) + { + #if VTK_MAJOR_VERSION <= 5 + filter->SetInput(polydata); + #else + filter->SetInputData(polydata); + #endif + } + + template + static inline void AddInputData(vtkSmartPointer filter, vtkPolyData *polydata) + { + #if VTK_MAJOR_VERSION <= 5 + filter->AddInput(polydata); + #else + filter->AddInputData(polydata); + #endif + } + }; } } diff --git a/modules/viz/src/vizcore.cpp b/modules/viz/src/vizcore.cpp index d01b947..ffb2d84 100644 --- a/modules/viz/src/vizcore.cpp +++ b/modules/viz/src/vizcore.cpp @@ -305,9 +305,7 @@ void cv::viz::writeTrajectory(InputArray _traj, const String& files_format, int void cv::viz::computeNormals(const Mesh3d& mesh, OutputArray _normals) { - vtkSmartPointer prop = WidgetAccessor::getProp(WMesh(mesh)); - vtkSmartPointer mapper = vtkActor::SafeDownCast(prop)->GetMapper(); - vtkSmartPointer polydata = vtkPolyData::SafeDownCast(mapper->GetInput()); + vtkSmartPointer polydata = getPolyData(WMesh(mesh)); vtkSmartPointer normal_generator = vtkSmartPointer::New(); #if VTK_MAJOR_VERSION <= 5 diff --git a/modules/viz/test/test_viz3d.cpp b/modules/viz/test/test_viz3d.cpp index ce0344f..6bc3622 100644 --- a/modules/viz/test/test_viz3d.cpp +++ b/modules/viz/test/test_viz3d.cpp @@ -45,37 +45,51 @@ using namespace cv; TEST(Viz_viz3d, develop) { - std::cout << std::string(cvtest::TS::ptr()->get_data_path()) + "dragon.ply" << std::endl; + cv::Mat cloud = cv::viz::readCloud(get_dragon_ply_file_path()); - cv::Mat cloud = cv::viz::readCloud(String(cvtest::TS::ptr()->get_data_path()) + "dragon.ply"); + //cv::viz::Mesh3d mesh = cv::viz::Mesh3d::load(get_dragon_ply_file_path()); - -// for(size_t i = 0; i < cloud.total(); ++i) -// { -// if (i % 15 == 0) -// continue; -// const static float qnan = std::numeric_limits::quiet_NaN(); -// cloud.at(i) = Vec3f(qnan, qnan, qnan); -// } + //theRNG().fill(mesh.colors, RNG::UNIFORM, 0, 255); cv::viz::Viz3d viz("abc"); viz.setBackgroundColor(cv::viz::Color::mlab()); viz.showWidget("coo", cv::viz::WCoordinateSystem(0.1)); - cv::Mat colors(cloud.size(), CV_8UC3, cv::Scalar(0, 255, 0)); + +// double c = cos(CV_PI/6); +// std::vector pts; +// pts.push_back(Vec3d(0, 0.0, -1.0)); +// pts.push_back(Vec3d(1, c, -0.5)); +// pts.push_back(Vec3d(2, c, 0.5)); +// pts.push_back(Vec3d(3, 0.0, 1.0)); +// pts.push_back(Vec3d(4, -c, 0.5)); +// pts.push_back(Vec3d(5, -c, -0.5)); + +// viz.showWidget("pl", cv::viz::WPolyLine(Mat(pts), cv::viz::Color::green())); + + //viz.showWidget("pl", cv::viz::WPolyLine(cloud.colRange(0, 100), cv::viz::Color::green())); + //viz.spin(); + + //cv::Mat colors(cloud.size(), CV_8UC3, cv::Scalar(0, 255, 0)); //viz.showWidget("h", cv::viz::Widget::fromPlyFile("d:/horse-red.ply")); //viz.showWidget("a", cv::viz::WArrow(cv::Point3f(0,0,0), cv::Point3f(1,1,1))); std::vector gt, es; cv::viz::readTrajectory(gt, "d:/Datasets/trajs/gt%05d.xml"); - cv::viz::readTrajectory(es, "d:/Datasets/trajs/es%05d.xml"); + //cv::viz::readTrajectory(es, "d:/Datasets/trajs/es%05d.xml"); + gt.resize(20); + + Affine3d inv = gt[0].inv(); + for(size_t i = 0; i < gt.size(); ++i) + gt[i] = inv * gt[i]; + + //viz.showWidget("gt", viz::WTrajectory(gt, viz::WTrajectory::PATH, 1.f, viz::Color::blue()), gt[0].inv()); + viz.showWidget("gt", viz::WTrajectory(gt, viz::WTrajectory::BOTH, 0.01f, viz::Color::blue())); - viz.showWidget("gt", viz::WTrajectory(gt, viz::WTrajectory::PATH, 1.f, viz::Color::blue()), gt[0].inv()); - viz.showWidget("tr", viz::WTrajectory(es, viz::WTrajectory::PATH, 1.f, viz::Color::red()), gt[0].inv()); + //viz.showWidget("tr", viz::WTrajectory(es, viz::WTrajectory::PATH, 1.f, viz::Color::red()), gt[0].inv()); - cv::RNG rng; - rng.fill(colors, cv::RNG::UNIFORM, 0, 255); + //theRNG().fill(colors, cv::RNG::UNIFORM, 0, 255); //viz.showWidget("c", cv::viz::WCloud(cloud, colors)); //viz.showWidget("c", cv::viz::WCloud(cloud, cv::viz::Color::bluberry()));