1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 Misc helper methods and utilities
27 \*---------------------------------------------------------------------------*/
29 #include "vtkPV3Readers.H"
35 #include "vtkDataArraySelection.h"
36 #include "vtkDataSet.h"
37 #include "vtkMultiBlockDataSet.h"
38 #include "vtkInformation.h"
40 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
42 defineTypeNameAndDebug(Foam::vtkPV3Readers, 0);
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 // Extract up to the first non-word characters
50 inline word getFirstWord(const char* str)
55 while (str[n] && word::valid(str[n]))
59 return word(str, n, true);
69 } // End namespace Foam
72 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
74 void Foam::vtkPV3Readers::AddToBlock
76 vtkMultiBlockDataSet* output,
78 const partInfo& selector,
79 const label datasetNo,
80 const std::string& datasetName
83 const int blockNo = selector.block();
85 vtkDataObject* blockDO = output->GetBlock(blockNo);
86 vtkMultiBlockDataSet* block = vtkMultiBlockDataSet::SafeDownCast(blockDO);
92 FatalErrorIn("Foam::vtkPV3Readers::AddToBlock")
93 << "Block already has a vtkDataSet assigned to it"
98 block = vtkMultiBlockDataSet::New();
99 output->SetBlock(blockNo, block);
105 Info<< "block[" << blockNo << "] has "
106 << block->GetNumberOfBlocks()
107 << " datasets prior to adding set " << datasetNo
108 << " with name: " << datasetName << endl;
111 block->SetBlock(datasetNo, dataset);
113 // name the block when assigning dataset 0
116 output->GetMetaData(blockNo)->Set
118 vtkCompositeDataSet::NAME(),
123 if (datasetName.size())
125 block->GetMetaData(datasetNo)->Set
127 vtkCompositeDataSet::NAME(),
134 vtkDataSet* Foam::vtkPV3Readers::GetDataSetFromBlock
136 vtkMultiBlockDataSet* output,
137 const partInfo& selector,
138 const label datasetNo
141 const int blockNo = selector.block();
143 vtkDataObject* blockDO = output->GetBlock(blockNo);
144 vtkMultiBlockDataSet* block = vtkMultiBlockDataSet::SafeDownCast(blockDO);
148 return vtkDataSet::SafeDownCast(block->GetBlock(datasetNo));
155 // ununsed at the moment
156 Foam::label Foam::vtkPV3Readers::GetNumberOfDataSets
158 vtkMultiBlockDataSet* output,
159 const partInfo& selector
162 const int blockNo = selector.block();
164 vtkDataObject* blockDO = output->GetBlock(blockNo);
165 vtkMultiBlockDataSet* block = vtkMultiBlockDataSet::SafeDownCast(blockDO);
168 return block->GetNumberOfBlocks();
175 // Foam::word Foam::vtkPV3Readers::getPartName(int partId)
177 // return getFirstWord(reader_->GetPartArrayName(partId));
181 Foam::wordHashSet Foam::vtkPV3Readers::getSelected
183 vtkDataArraySelection* select
186 int nElem = select->GetNumberOfArrays();
187 wordHashSet selections(2*nElem);
189 for (int elemI=0; elemI < nElem; ++elemI)
191 if (select->GetArraySetting(elemI))
193 selections.insert(getFirstWord(select->GetArrayName(elemI)));
201 Foam::wordHashSet Foam::vtkPV3Readers::getSelected
203 vtkDataArraySelection* select,
204 const partInfo& selector
207 int nElem = select->GetNumberOfArrays();
208 wordHashSet selections(2*nElem);
210 for (int elemI = selector.start(); elemI < selector.end(); ++elemI)
212 if (select->GetArraySetting(elemI))
214 selections.insert(getFirstWord(select->GetArrayName(elemI)));
222 Foam::stringList Foam::vtkPV3Readers::getSelectedArrayEntries
224 vtkDataArraySelection* select
227 stringList selections(select->GetNumberOfArrays());
230 forAll(selections, elemI)
232 if (select->GetArraySetting(elemI))
234 selections[nElem++] = select->GetArrayName(elemI);
237 selections.setSize(nElem);
242 label nElem = select->GetNumberOfArrays();
244 for (int elemI = 0; elemI < nElem; ++elemI)
246 Info<< " \"" << select->GetArrayName(elemI) << "\"";
248 Info<< " )\nselected(";
250 forAll(selections, elemI)
252 Info<< " " << selections[elemI];
261 Foam::stringList Foam::vtkPV3Readers::getSelectedArrayEntries
263 vtkDataArraySelection* select,
264 const partInfo& selector
267 stringList selections(selector.size());
270 for (int elemI = selector.start(); elemI < selector.end(); ++elemI)
272 if (select->GetArraySetting(elemI))
274 selections[nElem++] = select->GetArrayName(elemI);
277 selections.setSize(nElem);
283 for (int elemI = selector.start(); elemI < selector.end(); ++elemI)
285 Info<< " \"" << select->GetArrayName(elemI) << "\"";
287 Info<< " )\nselected(";
289 forAll(selections, elemI)
291 Info<< " " << selections[elemI];
300 void Foam::vtkPV3Readers::setSelectedArrayEntries
302 vtkDataArraySelection* select,
303 const stringList& selections
306 const int nElem = select->GetNumberOfArrays();
307 select->DisableAllArrays();
309 // Loop through entries, setting values from selectedEntries
310 for (int elemI=0; elemI < nElem; ++elemI)
312 string arrayName(select->GetArrayName(elemI));
314 forAll(selections, elemI)
316 if (selections[elemI] == arrayName)
318 select->EnableArray(arrayName.c_str());
326 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
329 // ************************************************************************* //