1793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/*M/////////////////////////////////////////////////////////////////////////////////////// 2793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// 3793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// 5793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// By downloading, copying, installing or using the software you agree to this license. 6793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// If you do not agree to this license, do not download, install, 7793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// copy or use the software. 8793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// 9793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// 10793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// License Agreement 11793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// For Open Source Computer Vision Library 12793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// 13793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// Copyright (C) 2013, OpenCV Foundation, all rights reserved. 14793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// Third party copyrights are property of their respective owners. 15793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// 16793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// Redistribution and use in source and binary forms, with or without modification, 17793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// are permitted provided that the following conditions are met: 18793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// 19793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// * Redistribution's of source code must retain the above copyright notice, 20793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// this list of conditions and the following disclaimer. 21793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// 22793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// * Redistribution's in binary form must reproduce the above copyright notice, 23793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// this list of conditions and the following disclaimer in the documentation 24793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// and/or other materials provided with the distribution. 25793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// 26793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// * The name of the copyright holders may not be used to endorse or promote products 27793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// derived from this software without specific prior written permission. 28793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// 29793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// This software is provided by the copyright holders and contributors "as is" and 30793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// any express or implied warranties, including, but not limited to, the implied 31793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// warranties of merchantability and fitness for a particular purpose are disclaimed. 32793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// In no event shall the Intel Corporation or contributors be liable for any direct, 33793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// indirect, incidental, special, exemplary, or consequential damages 34793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// (including, but not limited to, procurement of substitute goods or services; 35793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// loss of use, data, or profits; or business interruption) however caused 36793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// and on any theory of liability, whether in contract, strict liability, 37793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// or tort (including negligence or otherwise) arising in any way out of 38793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// the use of this software, even if advised of the possibility of such damage. 39793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// 40793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// Authors: 41793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com 42793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// 43793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//M*/ 44793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 45793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#include "precomp.hpp" 46793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 47793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslernamespace cv { namespace viz 48793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 49793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler vtkStandardNewMacro(vtkXYZReader); 50793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler}} 51793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 52793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 53793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslercv::viz::vtkXYZReader::vtkXYZReader() 54793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 55793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler this->FileName = 0; 56793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler this->SetNumberOfInputPorts(0); 57793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 58793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 59793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslercv::viz::vtkXYZReader::~vtkXYZReader() 60793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 61793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler this->SetFileName(0); 62793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 63793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 64793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslervoid cv::viz::vtkXYZReader::PrintSelf(ostream& os, vtkIndent indent) 65793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 66793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler this->Superclass::PrintSelf(os,indent); 67793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler os << indent << "FileName: " << (this->FileName ? this->FileName : "(none)") << "\n"; 68793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 69793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 70793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerint cv::viz::vtkXYZReader::RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector* outputVector) 71793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 72793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // Make sure we have a file to read. 73793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if(!this->FileName) 74793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 75793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler vtkErrorMacro("A FileName must be specified."); 76793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return 0; 77793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 78793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 79793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // Open the input file. 80793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler ifstream fin(this->FileName); 81793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if(!fin) 82793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 83793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler vtkErrorMacro("Error opening file " << this->FileName); 84793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return 0; 85793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 86793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 87793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // Allocate objects to hold points and vertex cells. 88793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New(); 89793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler vtkSmartPointer<vtkCellArray> verts = vtkSmartPointer<vtkCellArray>::New(); 90793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 91793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // Read points from the file. 92793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler vtkDebugMacro("Reading points from file " << this->FileName); 93793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler double x[3]; 94793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler while(fin >> x[0] >> x[1] >> x[2]) 95793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 96793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler vtkIdType id = points->InsertNextPoint(x); 97793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler verts->InsertNextCell(1, &id); 98793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 99793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler vtkDebugMacro("Read " << points->GetNumberOfPoints() << " points."); 100793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 101793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // Store the points and cells in the output data object. 102793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler vtkPolyData* output = vtkPolyData::GetData(outputVector); 103793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler output->SetPoints(points); 104793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler output->SetVerts(verts); 105793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 106793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return 1; 107793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 108