MCPcopy Create free account
hub / github.com/Kitware/VTK / ReadVariableArray

Method ReadVariableArray

IO/EnSight/core/EnSightDataSet.cxx:1771–1868  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

1769
1770//------------------------------------------------------------------------------
1771vtkSmartPointer<vtkFloatArray> EnSightDataSet::ReadVariableArray(
1772 EnSightFile& file, const std::string& sectionHeader, vtkIdType numElements, int numComponents)
1773{
1774 // handles reading float arrays for variables
1775 // handles partial and undefined values
1776 // undef gets converted to NaN because that is what VTK/ParaView uses
1777 std::regex regEx("^[^ ]+ ([^ ]+)");
1778 std::smatch sm;
1779 const bool match = std::regex_search(sectionHeader, sm, regEx);
1780 const bool hasUndef = (match && sm.str(1) == "undef");
1781 const bool hasPartial = (match && sm.str(1) == "partial");
1782
1783 float undefValue = 0;
1784 if (hasUndef)
1785 {
1786 file.ReadNumber(&undefValue);
1787 }
1788
1789 vtkNew<vtkIdList> partialIndices;
1790 if (hasPartial)
1791 {
1792 int count;
1793 file.ReadNumber(&count);
1794
1795 std::vector<int> buffer(count);
1796 file.ReadArray(&buffer.front(), count);
1797
1798 partialIndices->SetNumberOfIds(count);
1799 std::transform(buffer.begin(), buffer.end(), partialIndices->WritePointer(0, count),
1800 [](vtkIdType val)
1801 {
1802 return val - 1; /* since ensight indices start with 1*/
1803 });
1804 }
1805
1806 // replace undefined values with "internal undef" which in ParaView is NaN
1807 auto replaceUndef = [&](vtkFloatArray* farray)
1808 {
1809 if (hasUndef)
1810 {
1811 for (vtkIdType cc = 0; cc < numElements; ++cc)
1812 {
1813 if (farray->GetTypedComponent(cc, 0) == undefValue)
1814 {
1815 farray->SetTypedComponent(cc, 0, std::nanf("1"));
1816 }
1817 }
1818 }
1819 };
1820
1821 auto readComponent = [&](vtkIdType count)
1822 {
1823 vtkNew<vtkFloatArray> buffer;
1824 buffer->SetNumberOfTuples(count);
1825 if (hasPartial)
1826 {
1827 // fill with NaNs
1828 buffer->FillValue(std::nanf("1"));

Callers 2

ReadVariableNodesMethod · 0.95
ReadVariableElementsMethod · 0.95

Calls 15

getDestinationComponentFunction · 0.85
ReadNumberMethod · 0.80
SetNumberOfIdsMethod · 0.80
transformFunction · 0.50
strMethod · 0.45
ReadArrayMethod · 0.45
frontMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
WritePointerMethod · 0.45
GetTypedComponentMethod · 0.45
SetTypedComponentMethod · 0.45

Tested by

no test coverage detected