------------------------------------------------------------------------------
| 1769 | |
| 1770 | //------------------------------------------------------------------------------ |
| 1771 | vtkSmartPointer<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")); |
no test coverage detected