NEMoSys  0.63.0
A modular, extensible resource with robust automated mesh generation, mesh quality analysis, adaptive mesh refinement, and data transfer between arbitrary meshes.
TransferBase.C
Go to the documentation of this file.
1 /*******************************************************************************
2 * Promesh *
3 * Copyright (C) 2022, IllinoisRocstar LLC. All rights reserved. *
4 * *
5 * Promesh is the property of IllinoisRocstar LLC. *
6 * *
7 * IllinoisRocstar LLC *
8 * Champaign, IL *
9 * www.illinoisrocstar.com *
10 * promesh@illinoisrocstar.com *
11 *******************************************************************************/
12 /*******************************************************************************
13 * This file is part of Promesh *
14 * *
15 * This version of Promesh is free software: you can redistribute it and/or *
16 * modify it under the terms of the GNU Lesser General Public License as *
17 * published by the Free Software Foundation, either version 3 of the License, *
18 * or (at your option) any later version. *
19 * *
20 * Promesh is distributed in the hope that it will be useful, but WITHOUT ANY *
21 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more *
23 * details. *
24 * *
25 * You should have received a copy of the GNU Lesser General Public License *
26 * along with this program. If not, see <https://www.gnu.org/licenses/>. *
27 * *
28 *******************************************************************************/
29 #include "Transfer/TransferBase.H"
30 
31 #include <vtkCellData.h>
32 #include <vtkPointData.h>
33 
34  // transfer point data with given names from source to target
35  // (converts names to ids before passing to subclass)
36 int TransferBase::transferPointData(const std::vector<std::string> &arrayNames,
37  const std::vector<std::string> &newnames)
38 {
39  vtkPointData* pointData = source->getDataSet()->GetPointData();
40  std::vector<int> arrayIDs = getArrayIDs(arrayNames, pointData);
41 
42  return transferPointData(arrayIDs, newnames);
43 }
44 
45 // transfer cell data with given names from source to target - converts names to ids
46 // (see above)
47 int TransferBase::transferCellData(const std::vector<std::string> &arrayNames,
48  const std::vector<std::string> &newnames)
49 {
50  vtkCellData* cellData = source->getDataSet()->GetCellData();
51  std::vector<int> arrayIDs = getArrayIDs(arrayNames, cellData);
52 
53  return transferCellData(arrayIDs, newnames);
54 }
55 
56 std::vector<int> TransferBase::getArrayIDs(const std::vector<std::string>& arrayNames, vtkFieldData* fieldData)
57 {
58  std::vector<int> arrayIDs;
59  for(auto arrayName : arrayNames)
60  {
61  int arrayIndex = getDataArrayIndex(arrayName, fieldData);
62  if(arrayIndex == -1)
63  {
64  std::cerr << "Array " << arrayName << " not found." << std::endl;
65  exit(1);
66  }
67  arrayIDs.push_back(arrayIndex);
68  }
69  return arrayIDs;
70 }
71 
72 int TransferBase::getDataArrayIndex(const std::string& arrayName, vtkFieldData* data)
73 {
74  for(int arrayIndex = 0; arrayIndex < data->GetNumberOfArrays(); ++arrayIndex)
75  {
76  if(arrayName == data->GetArrayName(arrayIndex)) return arrayIndex;
77  }
78  return -1;
79 }
80 
data_type data
Edge/face with sorted point ids (a, b, c, ...) is located at some index i in data[b], with data[b][i].first == [a, c] (for edges, third point id treated as -1).
virtual int transferCellData(const std::vector< int > &arrayIDs, const std::vector< std::string > &newnames=std::vector< std::string >())=0
Transfer cell data with given ids from source to target.
int getDataArrayIndex(const std::string &arrayName, vtkFieldData *data)
given array name and field data, returns index of array with given name (-1 if not found) ...
Definition: TransferBase.C:72
vtkSmartPointer< vtkDataSet > getDataSet() const
get this meshes&#39; dataSet
Definition: meshBase.H:308
virtual int transferPointData(const std::vector< int > &arrayIDs, const std::vector< std::string > &newnames=std::vector< std::string >())=0
Transfer point data with given ids from source to target.
std::vector< int > getArrayIDs(const std::vector< std::string > &arrayNames, vtkFieldData *fieldData)
given array names and field data, return vector of corresponding array ids in the field data ...
Definition: TransferBase.C:56
meshBase * source
Definition: TransferBase.H:105