• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
5 //  By downloading, copying, installing or using the software you agree to this license.
6 //  If you do not agree to this license, do not download, install,
7 //  copy or use the software.
8 //
9 //
10 //                           License Agreement
11 //                For Open Source Computer Vision Library
12 //
13 // Copyright (C) 2013, OpenCV Foundation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
15 //
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
18 //
19 //   * Redistribution's of source code must retain the above copyright notice,
20 //     this list of conditions and the following disclaimer.
21 //
22 //   * Redistribution's in binary form must reproduce the above copyright notice,
23 //     this list of conditions and the following disclaimer in the documentation
24 //     and/or other materials provided with the distribution.
25 //
26 //   * The name of the copyright holders may not be used to endorse or promote products
27 //     derived from this software without specific prior written permission.
28 //
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
39 //
40 // Authors:
41 //  * Anatoly Baksheev, Itseez Inc.  myname.mysurname <> mycompany.com
42 //
43 //M*/
44 
45 #include "precomp.hpp"
46 
47 namespace cv { namespace viz
48 {
49     vtkStandardNewMacro(vtkTrajectorySource);
50 }}
51 
vtkTrajectorySource()52 cv::viz::vtkTrajectorySource::vtkTrajectorySource() { SetNumberOfInputPorts(0); }
~vtkTrajectorySource()53 cv::viz::vtkTrajectorySource::~vtkTrajectorySource() {}
54 
SetTrajectory(InputArray _traj)55 void cv::viz::vtkTrajectorySource::SetTrajectory(InputArray _traj)
56 {
57     CV_Assert(_traj.kind() == _InputArray::STD_VECTOR || _traj.kind() == _InputArray::MAT);
58     CV_Assert(_traj.type() == CV_32FC(16) || _traj.type() == CV_64FC(16));
59 
60     Mat traj;
61     _traj.getMat().convertTo(traj, CV_64F);
62     const Affine3d* dpath = traj.ptr<Affine3d>();
63     size_t total = traj.total();
64 
65     points = vtkSmartPointer<vtkPoints>::New();
66     points->SetDataType(VTK_DOUBLE);
67     points->SetNumberOfPoints((vtkIdType)total);
68 
69     tensors = vtkSmartPointer<vtkDoubleArray>::New();
70     tensors->SetNumberOfComponents(9);
71     tensors->SetNumberOfTuples((vtkIdType)total);
72 
73     for(size_t i = 0; i < total; ++i, ++dpath)
74     {
75         Matx33d R = dpath->rotation().t();  // transposed because of
76         tensors->SetTuple((vtkIdType)i, R.val);        // column major order
77 
78         Vec3d p = dpath->translation();
79         points->SetPoint((vtkIdType)i, p.val);
80     }
81 }
82 
ExtractPoints(InputArray _traj)83 cv::Mat cv::viz::vtkTrajectorySource::ExtractPoints(InputArray _traj)
84 {
85     CV_Assert(_traj.kind() == _InputArray::STD_VECTOR || _traj.kind() == _InputArray::MAT);
86     CV_Assert(_traj.type() == CV_32FC(16) || _traj.type() == CV_64FC(16));
87 
88     Mat points(1, (int)_traj.total(), CV_MAKETYPE(_traj.depth(), 3));
89     const Affine3d* dpath = _traj.getMat().ptr<Affine3d>();
90     const Affine3f* fpath = _traj.getMat().ptr<Affine3f>();
91 
92     if (_traj.depth() == CV_32F)
93         for(int i = 0; i < points.cols; ++i)
94             points.at<Vec3f>(i) = fpath[i].translation();
95 
96     if (_traj.depth() == CV_64F)
97         for(int i = 0; i < points.cols; ++i)
98             points.at<Vec3d>(i) = dpath[i].translation();
99 
100     return points;
101 }
102 
RequestData(vtkInformation * vtkNotUsed (request),vtkInformationVector ** vtkNotUsed (inputVector),vtkInformationVector * outputVector)103 int cv::viz::vtkTrajectorySource::RequestData(vtkInformation *vtkNotUsed(request), vtkInformationVector **vtkNotUsed(inputVector), vtkInformationVector *outputVector)
104 {
105     vtkInformation *outInfo = outputVector->GetInformationObject(0);
106     vtkPolyData *output = vtkPolyData::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
107     output->SetPoints(points);
108     output->GetPointData()->SetTensors(tensors);
109     return 1;
110 }
111