-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #465 from DLR-AMR/vtk_polydata_reader
Add vtk_poly_data_reader [vtk_to_cmesh 4/6]
- Loading branch information
Showing
4 changed files
with
172 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
src/t8_cmesh/t8_cmesh_vtk_to_t8/t8_cmesh_vtk_polydata.cxx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* | ||
This file is part of t8code. | ||
t8code is a C library to manage a collection (a forest) of multiple | ||
connected adaptive space-trees of general element classes in parallel. | ||
Copyright (C) 2015 the developers | ||
t8code 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. | ||
t8code 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 t8code; if not, write to the Free Software Foundation, Inc., | ||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
#include <t8_cmesh/t8_cmesh_vtk_to_t8/t8_cmesh_vtk_polydata.hxx> | ||
#if T8_WITH_VTK | ||
#include <vtkPolyData.h> | ||
#include <vtkBYUReader.h> | ||
#include <vtkOBJReader.h> | ||
#include <vtkPLYReader.h> | ||
#include <vtkPolyDataReader.h> | ||
#include <vtkSTLReader.h> | ||
#include <vtkXMLPolyDataReader.h> | ||
|
||
int | ||
t8_read_poly (const char *filename, vtkSmartPointer < vtkPolyData > grid) | ||
{ | ||
char tmp[BUFSIZ]; | ||
char *extension; | ||
/* Get the file-extension to decide which reader to use. */ | ||
strcpy (tmp, filename); | ||
extension = strrchr (tmp, '.') + 1; | ||
T8_ASSERT (strcmp (extension, "")); | ||
|
||
/* Check if we can open the file. */ | ||
FILE *first_check; | ||
first_check = fopen (filename, "r"); | ||
if (first_check == NULL) { | ||
t8_errorf ("Can not find the file %s\n", filename); | ||
fclose (first_check); | ||
return 1; | ||
} | ||
fclose (first_check); | ||
|
||
/* Read the file depending on the extension. Not all readers have | ||
* a built-in check if the file is readable. */ | ||
if (strcmp (extension, "ply") == 0) { | ||
vtkNew < vtkPLYReader > reader; | ||
reader->SetFileName (filename); | ||
reader->Update (); | ||
grid->ShallowCopy (reader->GetOutput ()); | ||
return 0; | ||
} | ||
else if (strcmp (extension, "vtp") == 0) { | ||
vtkNew < vtkXMLPolyDataReader > reader; | ||
reader->SetFileName (filename); | ||
if (!reader->CanReadFile (filename)) { | ||
t8_errorf ("Unable to read file %s.\n", filename); | ||
return 1; | ||
} | ||
reader->Update (); | ||
grid->ShallowCopy (reader->GetOutput ()); | ||
return 0; | ||
} | ||
else if (strcmp (extension, "obj") == 0) { | ||
vtkNew < vtkOBJReader > reader; | ||
reader->SetFileName (filename); | ||
reader->Update (); | ||
grid->ShallowCopy (reader->GetOutput ()); | ||
return 0; | ||
} | ||
else if (strcmp (extension, "stl") == 0) { | ||
vtkNew < vtkSTLReader > reader; | ||
reader->SetFileName (filename); | ||
reader->Update (); | ||
grid->ShallowCopy (reader->GetOutput ()); | ||
return 0; | ||
} | ||
else if (strcmp (extension, "vtk") == 0) { | ||
vtkNew < vtkPolyDataReader > reader; | ||
reader->SetFileName (filename); | ||
reader->Update (); | ||
if (!reader->IsFilePolyData ()) { | ||
t8_errorf | ||
("File-content is not polydata. If it is a vtkUnstructuredGrid use the unstructured Grid reader."); | ||
return 1; | ||
} | ||
grid->ShallowCopy (reader->GetOutput ()); | ||
return 0; | ||
} | ||
else if (strcmp (extension, "g") == 0) { | ||
vtkNew < vtkBYUReader > reader; | ||
reader->SetGeometryFileName (filename); | ||
reader->Update (); | ||
grid->ShallowCopy (reader->GetOutput ()); | ||
return 0; | ||
} | ||
else { | ||
/* Return NULL if the reader is not used correctly. */ | ||
t8_global_errorf | ||
("Please use .ply, .vtp, .obj, .stl, .vtk or .g file %s\n", filename); | ||
return 1; | ||
} | ||
} | ||
#endif /* T8_WITH_VTK */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
This file is part of t8code. | ||
t8code is a C library to manage a collection (a forest) of multiple | ||
connected adaptive space-trees of general element classes in parallel. | ||
Copyright (C) 2015 the developers | ||
t8code 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. | ||
t8code 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 t8code; if not, write to the Free Software Foundation, Inc., | ||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
/** | ||
* This file contains all helper functions to translate vtk-polydata. | ||
* | ||
*/ | ||
|
||
#ifndef T8_CMESH_VTK_POLYDATA | ||
#define T8_CMESH_VTK_POLYDATA | ||
|
||
#include <t8.h> | ||
#if T8_WITH_VTK | ||
#include <vtkPolyData.h> | ||
#include <vtkSmartPointer.h> | ||
#include <vtkCellData.h> | ||
#include <vtkDataSet.h> | ||
|
||
/** | ||
* Given a filename to a file containing Polydata, read | ||
* the file using the vtk-library. | ||
* | ||
* \param[in] filename The name of the file | ||
* \param[in, out] grid On input a vtkSmartPointer, that will hold the grid described in | ||
* \a filename. | ||
* \return 0 if the file was read successfully, non-zero otherwise. | ||
* | ||
*/ | ||
int t8_read_poly (const char *filename, | ||
vtkSmartPointer < vtkPolyData > grid); | ||
|
||
#endif /* T8_WITH_VTK */ | ||
|
||
#endif /* T8_CMESH_VTK_POLYDATA */ |