/*
Copyright 2008-2011 Pierre SMARS (smars@yuntech.edu.tw)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
#include "vtkUnstructuredGridWriter.h"
#include "vtkUnstructuredGrid.h"
#include "vtkPoints.h"
#include "vtkCellArray.h"
#include "vtkQuadraticTetra.h"
#include "vtkTetra.h"
#include
#include
#include "SimpleOpt.h"
enum { OPT_HELP };
//---------------------------------------------------------------------------
CSimpleOpt::SOption g_rgOptions[] = {
{ OPT_HELP, _T("-?"), SO_NONE },
{ OPT_HELP, _T("-h"), SO_NONE },
{ OPT_HELP, _T("--help"), SO_NONE },
SO_END_OF_OPTIONS
};
//---------------------------------------------------------------------------
int error(int val)
{
std::cerr << "tet2vtk:" << std::endl;
std::cerr << " create a 'vtk' file from a 'tet' file" << std::endl;
std::cerr << "syntax: tet2vtk [-?|-h|--help] < input_file > output_file" << std::endl;
std::cerr << "author: P.Smars, 2013" << std::endl;
std::cerr << "version 2013-11-11" << std::endl;
return val;
}
//---------------------------------------------------------------------------
int main( int argc, char *argv[] )
{
CSimpleOpt args(argc, argv, g_rgOptions);
while (args.Next())
{
if (args.LastError() == SO_SUCCESS)
{
if (args.OptionId() == OPT_HELP)
return error(0);
else
return error(-1);
} else {
std::cerr << "Invalid argument: " << args.OptionText() << std::endl;
return error(args.LastError());
}
}
if (args.FileCount() != 0) return error(-2);
// std::string name(args.File(0));
vtkPoints * pts = vtkPoints::New();
int npts;
std::cin >> npts;
for (int k = 0; k < npts; k++)
{
double x,y,z;
std::cin >> x >> y >> z;
pts->InsertNextPoint(x,y,z);
}
vtkUnstructuredGrid * data = vtkUnstructuredGrid::New();
data->SetPoints(pts);
pts->Delete();
//vtkCellArray * tetrahedrons = vtkCellArray::New();
int ntets;
std::cin >> ntets;
for (int k = 0; k < ntets; k++)
{
vtkIdType p[4];
for (int l = 0; l < 4; l++) std::cin >> p[l];
data->InsertNextCell(VTK_TETRA,4,p);
//tetrahedrons->InsertNextCell(4,p);
}
/* data->SetPolys(tetrahedrons);
tetrahedrons->Delete();*/
vtkUnstructuredGridWriter * writer = vtkUnstructuredGridWriter::New();
writer->SetInput(data);
// writer->SetFileName(name.c_str());
writer->SetFileName("/dev/stdout");
writer->Write();
return 0;
}