forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathvtkXMLMultiBlockDataWriter.cxx
120 lines (105 loc) · 3.77 KB
/
vtkXMLMultiBlockDataWriter.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*=========================================================================
Program: Visualization Toolkit
Module: vtkXMLMultiBlockDataWriter.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkXMLMultiBlockDataWriter.h"
#include "vtkCompositeDataIterator.h"
#include "vtkInformation.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkObjectFactory.h"
#include "vtkSmartPointer.h"
#include "vtkXMLDataElement.h"
vtkStandardNewMacro(vtkXMLMultiBlockDataWriter);
//----------------------------------------------------------------------------
vtkXMLMultiBlockDataWriter::vtkXMLMultiBlockDataWriter()
{
}
//----------------------------------------------------------------------------
vtkXMLMultiBlockDataWriter::~vtkXMLMultiBlockDataWriter()
{
}
//----------------------------------------------------------------------------
int vtkXMLMultiBlockDataWriter::FillInputPortInformation(
int vtkNotUsed(port), vtkInformation* info)
{
info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkMultiBlockDataSet");
return 1;
}
//----------------------------------------------------------------------------
int vtkXMLMultiBlockDataWriter::WriteComposite(vtkCompositeDataSet* compositeData,
vtkXMLDataElement* parent, int &writerIdx)
{
if (! (compositeData->IsA("vtkMultiBlockDataSet")
||compositeData->IsA("vtkMultiPieceDataSet")) )
{
vtkErrorMacro("Unsupported composite dataset type: "
<< compositeData->GetClassName() << ".");
return 0;
}
// Write each input.
vtkSmartPointer<vtkCompositeDataIterator> iter;
iter.TakeReference(compositeData->NewIterator());
iter->VisitOnlyLeavesOff();
iter->TraverseSubTreeOff();
iter->SkipEmptyNodesOff();
int index = 0;
int RetVal = 0;
for (iter->InitTraversal(); !iter->IsDoneWithTraversal();
iter->GoToNextItem(), index++)
{
vtkDataObject* curDO = iter->GetCurrentDataObject();
if (curDO && curDO->IsA("vtkCompositeDataSet"))
// if node is a supported composite dataset
// note in structure file and recurse.
{
vtkXMLDataElement* tag = vtkXMLDataElement::New();
if (curDO->IsA("vtkMultiPieceDataSet"))
{
tag->SetName("Piece");
tag->SetIntAttribute("index", index);
}
else if (curDO->IsA("vtkMultiBlockDataSet"))
{
tag->SetName("Block");
tag->SetIntAttribute("index", index);
}
vtkCompositeDataSet* curCD
= vtkCompositeDataSet::SafeDownCast(curDO);
if (!this->WriteComposite(curCD, tag, writerIdx))
{
tag->Delete();
return 0;
}
RetVal = 1;
parent->AddNestedElement(tag);
tag->Delete();
}
else
// this node is not a composite data set.
{
vtkXMLDataElement* datasetXML = vtkXMLDataElement::New();
datasetXML->SetName("DataSet");
datasetXML->SetIntAttribute("index", index);
vtkStdString fileName = this->CreatePieceFileName(writerIdx);
if (this->WriteNonCompositeData( curDO, datasetXML, writerIdx,
fileName.c_str()))
{
parent->AddNestedElement(datasetXML);
RetVal = 1;
}
datasetXML->Delete();
}
}
return RetVal;
}
//----------------------------------------------------------------------------
void vtkXMLMultiBlockDataWriter::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}