Path: blob/master/modules/viz/src/vtk/vtkTrajectorySource.cpp
16358 views
/*M///////////////////////////////////////////////////////////////////////////////////////1//2// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.3//4// By downloading, copying, installing or using the software you agree to this license.5// If you do not agree to this license, do not download, install,6// copy or use the software.7//8//9// License Agreement10// For Open Source Computer Vision Library11//12// Copyright (C) 2013, OpenCV Foundation, all rights reserved.13// Third party copyrights are property of their respective owners.14//15// Redistribution and use in source and binary forms, with or without modification,16// are permitted provided that the following conditions are met:17//18// * Redistribution's of source code must retain the above copyright notice,19// this list of conditions and the following disclaimer.20//21// * Redistribution's in binary form must reproduce the above copyright notice,22// this list of conditions and the following disclaimer in the documentation23// and/or other materials provided with the distribution.24//25// * The name of the copyright holders may not be used to endorse or promote products26// derived from this software without specific prior written permission.27//28// This software is provided by the copyright holders and contributors "as is" and29// any express or implied warranties, including, but not limited to, the implied30// warranties of merchantability and fitness for a particular purpose are disclaimed.31// In no event shall the Intel Corporation or contributors be liable for any direct,32// indirect, incidental, special, exemplary, or consequential damages33// (including, but not limited to, procurement of substitute goods or services;34// loss of use, data, or profits; or business interruption) however caused35// and on any theory of liability, whether in contract, strict liability,36// or tort (including negligence or otherwise) arising in any way out of37// the use of this software, even if advised of the possibility of such damage.38//39// Authors:40// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com41//42//M*/4344#include "../precomp.hpp"4546namespace cv { namespace viz47{48vtkStandardNewMacro(vtkTrajectorySource);49}}5051cv::viz::vtkTrajectorySource::vtkTrajectorySource() { SetNumberOfInputPorts(0); }52cv::viz::vtkTrajectorySource::~vtkTrajectorySource() {}5354void cv::viz::vtkTrajectorySource::SetTrajectory(InputArray _traj)55{56CV_Assert(_traj.kind() == _InputArray::STD_VECTOR || _traj.kind() == _InputArray::MAT);57CV_Assert(_traj.type() == CV_32FC(16) || _traj.type() == CV_64FC(16));5859Mat traj;60_traj.getMat().convertTo(traj, CV_64F);61const Affine3d* dpath = traj.ptr<Affine3d>();62size_t total = traj.total();6364points = vtkSmartPointer<vtkPoints>::New();65points->SetDataType(VTK_DOUBLE);66points->SetNumberOfPoints((vtkIdType)total);6768tensors = vtkSmartPointer<vtkDoubleArray>::New();69tensors->SetNumberOfComponents(9);70tensors->SetNumberOfTuples((vtkIdType)total);7172for(size_t i = 0; i < total; ++i, ++dpath)73{74Matx33d R = dpath->rotation().t(); // transposed because of75tensors->SetTuple((vtkIdType)i, R.val); // column major order7677Vec3d p = dpath->translation();78points->SetPoint((vtkIdType)i, p.val);79}80}8182cv::Mat cv::viz::vtkTrajectorySource::ExtractPoints(InputArray _traj)83{84CV_Assert(_traj.kind() == _InputArray::STD_VECTOR || _traj.kind() == _InputArray::MAT);85CV_Assert(_traj.type() == CV_32FC(16) || _traj.type() == CV_64FC(16));8687Mat points(1, (int)_traj.total(), CV_MAKETYPE(_traj.depth(), 3));88const Affine3d* dpath = _traj.getMat().ptr<Affine3d>();89const Affine3f* fpath = _traj.getMat().ptr<Affine3f>();9091if (_traj.depth() == CV_32F)92for(int i = 0; i < points.cols; ++i)93points.at<Vec3f>(i) = fpath[i].translation();9495if (_traj.depth() == CV_64F)96for(int i = 0; i < points.cols; ++i)97points.at<Vec3d>(i) = dpath[i].translation();9899return points;100}101102int cv::viz::vtkTrajectorySource::RequestData(vtkInformation *vtkNotUsed(request), vtkInformationVector **vtkNotUsed(inputVector), vtkInformationVector *outputVector)103{104vtkInformation *outInfo = outputVector->GetInformationObject(0);105vtkPolyData *output = vtkPolyData::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));106output->SetPoints(points);107output->GetPointData()->SetTensors(tensors);108return 1;109}110111112