#include <vtkDoubleArray.h>
#include <vtkPointData.h>
#include <vtkPolyData.h>
-#include <vtkPolyDataReader.h>
#include <vtkPolyDataMapper.h>
#include <vtkDataSetMapper.h>
#include <vtkCellArray.h>
#include <vtkObjectFactory.h>
#include <vtkPolyDataAlgorithm.h>
#include <vtkMergeFilter.h>
-#include <vtkDataSetWriter.h>
#include <vtkErrorCode.h>
#include <vtkPLYWriter.h>
#include <vtkSTLWriter.h>
-#include <vtkSimplePointsReader.h>
#include <vtkPLYReader.h>
#include <vtkOBJReader.h>
#include <vtkSTLReader.h>
#include <vtk/vtkOBJWriter.h>
#include <vtk/vtkXYZWriter.h>
+#include <vtk/vtkXYZReader.h>
#include <vtk/vtkCloudMatSink.h>
#include <vtk/vtkCloudMatSource.h>
#include <vtk/vtkTrajectorySource.h>
vtkSmartPointer<vtkPolyDataAlgorithm> reader;
if (extention == ".xyz")
{
- reader = vtkSmartPointer<vtkSimplePointsReader>::New();
- vtkSimplePointsReader::SafeDownCast(reader)->SetFileName(file.c_str());
+ reader = vtkSmartPointer<vtkXYZReader>::New();
+ vtkXYZReader::SafeDownCast(reader)->SetFileName(file.c_str());
}
else if (extention == ".ply")
{
os << indent << "Colors: " << colors.needed() << "\n";
os << indent << "Normals: " << normals.needed() << "\n";
}
+
+int cv::viz::vtkCloudMatSink::FillInputPortInformation(int, vtkInformation *info)
+{
+ info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkPolyData");
+ return 1;
+}
+
+vtkPolyData* cv::viz::vtkCloudMatSink::GetInput()
+{
+ return vtkPolyData::SafeDownCast(this->Superclass::GetInput());
+}
+
+vtkPolyData* cv::viz::vtkCloudMatSink::GetInput(int port)
+{
+ return vtkPolyData::SafeDownCast(this->Superclass::GetInput(port));
+}
#define __vtkCloudMatSink_h
#include <opencv2/core/core.hpp>
-#include <vtkPolyDataWriter.h>
+#include <vtkWriter.h>
namespace cv
{
namespace viz
{
- class vtkCloudMatSink : public vtkPolyDataWriter
+ class vtkCloudMatSink : public vtkWriter
{
public:
static vtkCloudMatSink *New();
- vtkTypeMacro(vtkCloudMatSink,vtkPolyDataWriter)
+ vtkTypeMacro(vtkCloudMatSink,vtkWriter)
void PrintSelf(ostream& os, vtkIndent indent);
void SetOutput(OutputArray cloud, OutputArray colors = noArray(), OutputArray normals = noArray(), OutputArray tcoords = noArray());
+ // Description:
+ // Get the input to this writer.
+ vtkPolyData* GetInput();
+ vtkPolyData* GetInput(int port);
+
protected:
vtkCloudMatSink();
~vtkCloudMatSink();
void WriteData();
+ int FillInputPortInformation(int port, vtkInformation *info);
_OutputArray cloud, colors, normals, tcoords;
std::ofstream fout; // only used to extract the default precision
this->DecimalPrecision = fout.precision();
this->FileName = NULL;
- this->FileType = VTK_ASCII;
}
cv::viz::vtkOBJWriter::~vtkOBJWriter(){}
if (!input)
return;
- std::ostream *outfilep = this->OpenVTKFile();
- if (!outfilep)
+ if (!this->FileName )
+ {
+ vtkErrorMacro(<< "No FileName specified! Can't write!");
+ this->SetErrorCode(vtkErrorCode::NoFileNameError);
+ return;
+ }
+
+ vtkDebugMacro(<<"Opening vtk file for writing...");
+ ostream *outfilep = new ofstream(this->FileName, ios::out);
+ if (outfilep->fail())
+ {
+ vtkErrorMacro(<< "Unable to open file: "<< this->FileName);
+ this->SetErrorCode(vtkErrorCode::CannotOpenFileError);
+ delete outfilep;
return;
+ }
std::ostream& outfile = *outfilep;
}
} /* if (input->GetNumberOfStrips() > 0) */
- this->CloseVTKFile(outfilep);
+ vtkDebugMacro(<<"Closing vtk file\n");
+ delete outfilep;
// Delete the file if an error occurred
if (this->ErrorCode == vtkErrorCode::OutOfDiskSpaceError)
Superclass::PrintSelf(os, indent);
os << indent << "DecimalPrecision: " << DecimalPrecision << "\n";
}
+
+int cv::viz::vtkOBJWriter::FillInputPortInformation(int, vtkInformation *info)
+{
+ info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkPolyData");
+ return 1;
+}
+
+vtkPolyData* cv::viz::vtkOBJWriter::GetInput()
+{
+ return vtkPolyData::SafeDownCast(this->Superclass::GetInput());
+}
+
+vtkPolyData* cv::viz::vtkOBJWriter::GetInput(int port)
+{
+ return vtkPolyData::SafeDownCast(this->Superclass::GetInput(port));
+}
#ifndef __vtkOBJWriter_h
#define __vtkOBJWriter_h
-#include <vtkPolyDataWriter.h>
+#include <vtkWriter.h>
namespace cv
{
namespace viz
{
- class vtkOBJWriter : public vtkPolyDataWriter
+ class vtkOBJWriter : public vtkWriter
{
public:
static vtkOBJWriter *New();
- vtkTypeMacro(vtkOBJWriter,vtkPolyDataWriter)
+ vtkTypeMacro(vtkOBJWriter,vtkWriter)
void PrintSelf(ostream& os, vtkIndent indent);
- vtkGetMacro(DecimalPrecision, int);
- vtkSetMacro(DecimalPrecision, int);
+ vtkGetMacro(DecimalPrecision, int)
+ vtkSetMacro(DecimalPrecision, int)
+
+ // Description:
+ // Specify file name of data file to write.
+ vtkSetStringMacro(FileName)
+ vtkGetStringMacro(FileName)
+
+ // Description:
+ // Get the input to this writer.
+ vtkPolyData* GetInput();
+ vtkPolyData* GetInput(int port);
protected:
vtkOBJWriter();
~vtkOBJWriter();
void WriteData();
+ int FillInputPortInformation(int port, vtkInformation *info);
int DecimalPrecision;
+ char *FileName;
private:
vtkOBJWriter(const vtkOBJWriter&); // Not implemented.
--- /dev/null
+/*M///////////////////////////////////////////////////////////////////////////////////////
+//
+// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
+//
+// By downloading, copying, installing or using the software you agree to this license.
+// If you do not agree to this license, do not download, install,
+// copy or use the software.
+//
+//
+// License Agreement
+// For Open Source Computer Vision Library
+//
+// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
+// Third party copyrights are property of their respective owners.
+//
+// Redistribution and use in source and binary forms, with or without modification,
+// are permitted provided that the following conditions are met:
+//
+// * Redistribution's of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+//
+// * Redistribution's in binary form must reproduce the above copyright notice,
+// this list of conditions and the following disclaimer in the documentation
+// and/or other materials provided with the distribution.
+//
+// * The name of the copyright holders may not be used to endorse or promote products
+// derived from this software without specific prior written permission.
+//
+// This software is provided by the copyright holders and contributors "as is" and
+// any express or implied warranties, including, but not limited to, the implied
+// warranties of merchantability and fitness for a particular purpose are disclaimed.
+// In no event shall the Intel Corporation or contributors be liable for any direct,
+// indirect, incidental, special, exemplary, or consequential damages
+// (including, but not limited to, procurement of substitute goods or services;
+// loss of use, data, or profits; or business interruption) however caused
+// and on any theory of liability, whether in contract, strict liability,
+// or tort (including negligence or otherwise) arising in any way out of
+// the use of this software, even if advised of the possibility of such damage.
+//
+// Authors:
+// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
+//
+//M*/
+
+#include "precomp.hpp"
+
+namespace cv { namespace viz
+{
+ vtkStandardNewMacro(vtkXYZReader);
+}}
+
+
+cv::viz::vtkXYZReader::vtkXYZReader()
+{
+ this->FileName = 0;
+ this->SetNumberOfInputPorts(0);
+}
+
+cv::viz::vtkXYZReader::~vtkXYZReader()
+{
+ this->SetFileName(0);
+}
+
+void cv::viz::vtkXYZReader::PrintSelf(ostream& os, vtkIndent indent)
+{
+ this->Superclass::PrintSelf(os,indent);
+ os << indent << "FileName: " << (this->FileName ? this->FileName : "(none)") << "\n";
+}
+
+int cv::viz::vtkXYZReader::RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector* outputVector)
+{
+ // Make sure we have a file to read.
+ if(!this->FileName)
+ {
+ vtkErrorMacro("A FileName must be specified.");
+ return 0;
+ }
+
+ // Open the input file.
+ ifstream fin(this->FileName);
+ if(!fin)
+ {
+ vtkErrorMacro("Error opening file " << this->FileName);
+ return 0;
+ }
+
+ // Allocate objects to hold points and vertex cells.
+ vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
+ vtkSmartPointer<vtkCellArray> verts = vtkSmartPointer<vtkCellArray>::New();
+
+ // Read points from the file.
+ vtkDebugMacro("Reading points from file " << this->FileName);
+ double x[3];
+ while(fin >> x[0] >> x[1] >> x[2])
+ {
+ vtkIdType id = points->InsertNextPoint(x);
+ verts->InsertNextCell(1, &id);
+ }
+ vtkDebugMacro("Read " << points->GetNumberOfPoints() << " points.");
+
+ // Store the points and cells in the output data object.
+ vtkPolyData* output = vtkPolyData::GetData(outputVector);
+ output->SetPoints(points);
+ output->SetVerts(verts);
+
+ return 1;
+}
--- /dev/null
+/*M///////////////////////////////////////////////////////////////////////////////////////
+//
+// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
+//
+// By downloading, copying, installing or using the software you agree to this license.
+// If you do not agree to this license, do not download, install,
+// copy or use the software.
+//
+//
+// License Agreement
+// For Open Source Computer Vision Library
+//
+// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
+// Third party copyrights are property of their respective owners.
+//
+// Redistribution and use in source and binary forms, with or without modification,
+// are permitted provided that the following conditions are met:
+//
+// * Redistribution's of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+//
+// * Redistribution's in binary form must reproduce the above copyright notice,
+// this list of conditions and the following disclaimer in the documentation
+// and/or other materials provided with the distribution.
+//
+// * The name of the copyright holders may not be used to endorse or promote products
+// derived from this software without specific prior written permission.
+//
+// This software is provided by the copyright holders and contributors "as is" and
+// any express or implied warranties, including, but not limited to, the implied
+// warranties of merchantability and fitness for a particular purpose are disclaimed.
+// In no event shall the Intel Corporation or contributors be liable for any direct,
+// indirect, incidental, special, exemplary, or consequential damages
+// (including, but not limited to, procurement of substitute goods or services;
+// loss of use, data, or profits; or business interruption) however caused
+// and on any theory of liability, whether in contract, strict liability,
+// or tort (including negligence or otherwise) arising in any way out of
+// the use of this software, even if advised of the possibility of such damage.
+//
+// Authors:
+// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
+//
+//M*/
+
+#ifndef __vtkXYZReader_h
+#define __vtkXYZReader_h
+
+#include "vtkPolyDataAlgorithm.h"
+
+namespace cv
+{
+ namespace viz
+ {
+ class vtkXYZReader : public vtkPolyDataAlgorithm
+ {
+ public:
+ static vtkXYZReader* New();
+ vtkTypeMacro(vtkXYZReader,vtkPolyDataAlgorithm)
+ void PrintSelf(ostream& os, vtkIndent indent);
+
+ // Description:
+ // Set/Get the name of the file from which to read points.
+ vtkSetStringMacro(FileName)
+ vtkGetStringMacro(FileName)
+
+ protected:
+ vtkXYZReader();
+ ~vtkXYZReader();
+
+ char* FileName;
+
+ int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*);
+ private:
+ vtkXYZReader(const vtkXYZReader&); // Not implemented.
+ void operator=(const vtkXYZReader&); // Not implemented.
+ };
+ }
+}
+
+#endif
if (!input)
return;
- // OpenVTKFile() will report any errors that happen
- ostream *outfilep = this->OpenVTKFile();
- if (!outfilep)
+ if (!this->FileName )
+ {
+ vtkErrorMacro(<< "No FileName specified! Can't write!");
+ this->SetErrorCode(vtkErrorCode::NoFileNameError);
+ return;
+ }
+
+ vtkDebugMacro(<<"Opening vtk file for writing...");
+ ostream *outfilep = new ofstream(this->FileName, ios::out);
+ if (outfilep->fail())
+ {
+ vtkErrorMacro(<< "Unable to open file: "<< this->FileName);
+ this->SetErrorCode(vtkErrorCode::CannotOpenFileError);
+ delete outfilep;
return;
+ }
ostream &outfile = *outfilep;
}
// Close the file
- this->CloseVTKFile(outfilep);
+ vtkDebugMacro(<<"Closing vtk file\n");
+ delete outfilep;
// Delete the file if an error occurred
if (this->ErrorCode == vtkErrorCode::OutOfDiskSpaceError)
}
}
+int cv::viz::vtkXYZWriter::FillInputPortInformation(int, vtkInformation *info)
+{
+ info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkPolyData");
+ return 1;
+}
+
void cv::viz::vtkXYZWriter::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
os << indent << "DecimalPrecision: " << this->DecimalPrecision << "\n";
}
+
+vtkPolyData* cv::viz::vtkXYZWriter::GetInput()
+{
+ return vtkPolyData::SafeDownCast(this->Superclass::GetInput());
+}
+
+vtkPolyData* cv::viz::vtkXYZWriter::GetInput(int port)
+{
+ return vtkPolyData::SafeDownCast(this->Superclass::GetInput(port));
+}
#ifndef __vtkXYZWriter_h
#define __vtkXYZWriter_h
-#include "vtkPolyDataWriter.h"
+#include "vtkWriter.h"
namespace cv
{
namespace viz
{
- class vtkXYZWriter : public vtkPolyDataWriter
+ class vtkXYZWriter : public vtkWriter
{
public:
static vtkXYZWriter *New();
- vtkTypeMacro(vtkXYZWriter,vtkPolyDataWriter)
+ vtkTypeMacro(vtkXYZWriter,vtkWriter)
void PrintSelf(ostream& os, vtkIndent indent);
vtkGetMacro(DecimalPrecision, int)
vtkSetMacro(DecimalPrecision, int)
+ // Description:
+ // Specify file name of data file to write.
+ vtkSetStringMacro(FileName)
+ vtkGetStringMacro(FileName)
+
+ // Description:
+ // Get the input to this writer.
+ vtkPolyData* GetInput();
+ vtkPolyData* GetInput(int port);
+
protected:
vtkXYZWriter();
~vtkXYZWriter(){}
void WriteData();
+ int FillInputPortInformation(int port, vtkInformation *info);
int DecimalPrecision;
+ char *FileName;
private:
vtkXYZWriter(const vtkXYZWriter&); // Not implemented.