Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
VTK
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Erik Palmer
VTK
Commits
c8bec1f2
Commit
c8bec1f2
authored
11 years ago
by
David C. Lonie
Browse files
Options
Downloads
Patches
Plain Diff
Handle polyhedra in vtkUnstructuredGridWriter.
Change-Id: I6c20eb8650e2b079c8b1f581c9727a3d8205087a
parent
42b0733e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
IO/Legacy/vtkUnstructuredGridWriter.cxx
+104
-5
104 additions, 5 deletions
IO/Legacy/vtkUnstructuredGridWriter.cxx
IO/Legacy/vtkUnstructuredGridWriter.h
+3
-0
3 additions, 0 deletions
IO/Legacy/vtkUnstructuredGridWriter.h
with
107 additions
and
5 deletions
IO/Legacy/vtkUnstructuredGridWriter.cxx
+
104
−
5
View file @
c8bec1f2
...
...
@@ -16,10 +16,17 @@
#include
"vtkByteSwap.h"
#include
"vtkCellArray.h"
#include
"vtkCellIterator.h"
#include
"vtkErrorCode.h"
#include
"vtkInformation.h"
#include
"vtkObjectFactory.h"
#include
"vtkSmartPointer.h"
#include
"vtkUnstructuredGrid.h"
#include
<algorithm>
#include
<iterator>
#include
<vector>
#if !defined(_WIN32) || defined(__CYGWIN__)
# include <unistd.h>
/* unlink */
#else
...
...
@@ -69,12 +76,29 @@ void vtkUnstructuredGridWriter::WriteData()
unlink
(
this
->
FileName
);
return
;
}
if
(
!
this
->
WriteCells
(
fp
,
input
->
GetCells
(),
"CELLS"
))
// Write cells. Check for faces so that we can handle them if present:
if
(
input
->
GetFaces
()
!=
NULL
)
{
vtkErrorMacro
(
"Ran out of disk space; deleting file: "
<<
this
->
FileName
);
this
->
CloseVTKFile
(
fp
);
unlink
(
this
->
FileName
);
return
;
// Handle face data:
if
(
!
this
->
WriteCellsAndFaces
(
fp
,
input
,
"CELLS"
))
{
vtkErrorMacro
(
"Ran out of disk space; deleting file: "
<<
this
->
FileName
);
this
->
CloseVTKFile
(
fp
);
unlink
(
this
->
FileName
);
return
;
}
}
else
{
// Fall back to superclass:
if
(
!
this
->
WriteCells
(
fp
,
input
->
GetCells
(),
"CELLS"
))
{
vtkErrorMacro
(
"Ran out of disk space; deleting file: "
<<
this
->
FileName
);
this
->
CloseVTKFile
(
fp
);
unlink
(
this
->
FileName
);
return
;
}
}
//
...
...
@@ -124,6 +148,81 @@ void vtkUnstructuredGridWriter::WriteData()
this
->
CloseVTKFile
(
fp
);
}
int
vtkUnstructuredGridWriter
::
WriteCellsAndFaces
(
ostream
*
fp
,
vtkUnstructuredGrid
*
grid
,
const
char
*
label
)
{
if
(
!
grid
->
GetCells
())
{
return
1
;
}
// Create a copy of the cell data with the face streams expanded.
// Do this before writing anything so that we know the size.
// Use ints to represent vtkIdTypes, since that's what the superclass does.
std
::
vector
<
int
>
cells
;
cells
.
reserve
(
grid
->
GetNumberOfCells
()
*
grid
->
GetMaxCellSize
());
vtkSmartPointer
<
vtkCellIterator
>
it
=
vtkSmartPointer
<
vtkCellIterator
>::
Take
(
grid
->
NewCellIterator
());
for
(
it
->
InitTraversal
();
!
it
->
IsDoneWithTraversal
();
it
->
GoToNextCell
())
{
if
(
it
->
GetCellType
()
!=
VTK_POLYHEDRON
)
{
vtkIdType
cellSize
=
it
->
GetNumberOfPoints
();
cells
.
push_back
(
static_cast
<
int
>
(
cellSize
));
std
::
copy
(
it
->
GetPointIds
()
->
GetPointer
(
0
),
it
->
GetPointIds
()
->
GetPointer
(
cellSize
),
std
::
back_inserter
(
cells
));
}
else
{
vtkIdType
cellSize
=
it
->
GetFaces
()
->
GetNumberOfIds
();
cells
.
push_back
(
static_cast
<
int
>
(
cellSize
));
std
::
copy
(
it
->
GetFaces
()
->
GetPointer
(
0
),
it
->
GetFaces
()
->
GetPointer
(
cellSize
),
std
::
back_inserter
(
cells
));
}
}
if
(
cells
.
empty
())
{
// Nothing to do.
return
1
;
}
*
fp
<<
label
<<
" "
<<
grid
->
GetNumberOfCells
()
<<
" "
<<
cells
.
size
()
<<
"
\n
"
;
if
(
this
->
FileType
==
VTK_ASCII
)
{
// Write each cell out to a separate line, must traverse:
std
::
vector
<
int
>::
const_iterator
cellStart
=
cells
.
begin
();
std
::
vector
<
int
>::
const_iterator
cellEnd
;
vtkIdType
nCells
=
grid
->
GetNumberOfCells
();
while
(
nCells
--
>
0
)
{
cellEnd
=
cellStart
+
(
*
cellStart
+
1
);
while
(
cellStart
!=
cellEnd
)
*
fp
<<
static_cast
<
int
>
(
*
cellStart
++
)
<<
" "
;
*
fp
<<
"
\n
"
;
}
}
else
{
// Just dump the cell data
vtkByteSwap
::
SwapWrite4BERange
(
&
cells
[
0
],
cells
.
size
(),
fp
);
*
fp
<<
"
\n
"
;
}
fp
->
flush
();
if
(
fp
->
fail
())
{
this
->
SetErrorCode
(
vtkErrorCode
::
OutOfDiskSpaceError
);
return
0
;
}
return
1
;
}
int
vtkUnstructuredGridWriter
::
FillInputPortInformation
(
int
,
vtkInformation
*
info
)
{
...
...
This diff is collapsed.
Click to expand it.
IO/Legacy/vtkUnstructuredGridWriter.h
+
3
−
0
View file @
c8bec1f2
...
...
@@ -44,6 +44,9 @@ protected:
void
WriteData
();
int
WriteCellsAndFaces
(
ostream
*
fp
,
vtkUnstructuredGrid
*
grid
,
const
char
*
label
);
virtual
int
FillInputPortInformation
(
int
port
,
vtkInformation
*
info
);
private
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment