Updated cloud io functionality - removed dependency from VTK legacy
This commit is contained in:
parent
63dbe66b41
commit
eb8728d727
@ -76,7 +76,6 @@
|
||||
#include <vtkDoubleArray.h>
|
||||
#include <vtkPointData.h>
|
||||
#include <vtkPolyData.h>
|
||||
#include <vtkPolyDataReader.h>
|
||||
#include <vtkPolyDataMapper.h>
|
||||
#include <vtkDataSetMapper.h>
|
||||
#include <vtkCellArray.h>
|
||||
@ -115,11 +114,9 @@
|
||||
#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>
|
||||
@ -142,6 +139,7 @@
|
||||
|
||||
#include <vtk/vtkOBJWriter.h>
|
||||
#include <vtk/vtkXYZWriter.h>
|
||||
#include <vtk/vtkXYZReader.h>
|
||||
#include <vtk/vtkCloudMatSink.h>
|
||||
#include <vtk/vtkCloudMatSource.h>
|
||||
#include <vtk/vtkTrajectorySource.h>
|
||||
|
@ -173,8 +173,8 @@ cv::Mat cv::viz::readCloud(const String& file, OutputArray colors, OutputArray n
|
||||
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")
|
||||
{
|
||||
|
@ -156,3 +156,19 @@ void cv::viz::vtkCloudMatSink::PrintSelf(ostream& os, vtkIndent indent)
|
||||
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));
|
||||
}
|
||||
|
@ -46,26 +46,32 @@
|
||||
#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;
|
||||
|
||||
|
@ -54,7 +54,6 @@ cv::viz::vtkOBJWriter::vtkOBJWriter()
|
||||
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(){}
|
||||
@ -65,9 +64,22 @@ void cv::viz::vtkOBJWriter::WriteData()
|
||||
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;
|
||||
|
||||
@ -224,7 +236,8 @@ void cv::viz::vtkOBJWriter::WriteData()
|
||||
}
|
||||
} /* 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)
|
||||
@ -239,3 +252,19 @@ void cv::viz::vtkOBJWriter::PrintSelf(ostream& os, vtkIndent indent)
|
||||
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));
|
||||
}
|
||||
|
@ -45,29 +45,41 @@
|
||||
#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.
|
||||
|
107
modules/viz/src/vtk/vtkXYZReader.cpp
Normal file
107
modules/viz/src/vtk/vtkXYZReader.cpp
Normal file
@ -0,0 +1,107 @@
|
||||
/*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;
|
||||
}
|
80
modules/viz/src/vtk/vtkXYZReader.h
Normal file
80
modules/viz/src/vtk/vtkXYZReader.h
Normal file
@ -0,0 +1,80 @@
|
||||
/*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
|
@ -61,10 +61,22 @@ void cv::viz::vtkXYZWriter::WriteData()
|
||||
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;
|
||||
|
||||
@ -76,7 +88,8 @@ void cv::viz::vtkXYZWriter::WriteData()
|
||||
}
|
||||
|
||||
// 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)
|
||||
@ -86,8 +99,24 @@ void cv::viz::vtkXYZWriter::WriteData()
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
@ -45,29 +45,41 @@
|
||||
#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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user