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

Method ReadArray

IO/Legacy/vtkDataReader.cxx:1543–2088  ·  view source on GitHub ↗

------------------------------------------------------------------------------ Description: Read data array. Return pointer to array object if successful read; otherwise return nullptr. Note: this method instantiates a reference counted object with initial count of one; proper protocol is for you to assign the data object and then invoke Delete() it to restore proper reference count.

Source from the content-addressed store, hash-verified

1541// the data object and then invoke Delete() it to restore proper reference
1542// count.
1543vtkAbstractArray* vtkDataReader::ReadArray(
1544 const char* dataType, vtkIdType numTuples, vtkIdType numComp)
1545{
1546 char* type = strdup(dataType);
1547 type = this->LowerCase(type);
1548
1549 vtkAbstractArray* array;
1550 if (!strncmp(type, "bit", 3))
1551 {
1552 array = vtkBitArray::New();
1553 array->SetNumberOfComponents(numComp);
1554 if (numTuples != 0 && numComp != 0)
1555 {
1556 unsigned char* ptr = ((vtkBitArray*)array)->WritePointer(0, numTuples * numComp);
1557 if (this->FileType == VTK_BINARY)
1558 {
1559 char line[256];
1560 this->IS->getline(line, 256);
1561 this->IS->read((char*)ptr, sizeof(unsigned char) * (numTuples * numComp + 7) / 8);
1562 if (this->IS->eof())
1563 {
1564 vtkErrorMacro(<< "Error reading binary bit array!");
1565 free(type);
1566 array->Delete();
1567 return nullptr;
1568 }
1569 }
1570 else
1571 {
1572 vtkIdType b;
1573 for (vtkIdType i = 0; i < numTuples; i++)
1574 {
1575 for (vtkIdType j = 0; j < numComp; j++)
1576 {
1577 if (!this->Read(&b))
1578 {
1579 vtkErrorMacro("Error reading ascii bit array! tuple: " << i << ", component: " << j);
1580 free(type);
1581 array->Delete();
1582 return nullptr;
1583 }
1584 else
1585 {
1586 ((vtkBitArray*)array)->SetValue(i * numComp + j, b);
1587 }
1588 }
1589 }
1590 }
1591 }
1592 }
1593
1594 else if (!strcmp(type, "char") || !strcmp(type, "signed_char"))
1595 {
1596 array = vtkCharArray::New();
1597 array->SetNumberOfComponents(numComp);
1598 char* ptr = ((vtkCharArray*)array)->WritePointer(0, numTuples * numComp);
1599 if (this->FileType == VTK_BINARY)
1600 {

Callers 15

ReadPointCoordinatesMethod · 0.95
ReadCoordinatesMethod · 0.95
ReadScalarDataMethod · 0.95
ReadVectorDataMethod · 0.95
ReadNormalDataMethod · 0.95
ReadTensorDataMethod · 0.95
ReadCoScalarDataMethod · 0.95
ReadTCoordsDataMethod · 0.95
ReadGlobalIdsMethod · 0.95
ReadPedigreeIdsMethod · 0.95
ReadEdgeFlagsMethod · 0.95
ReadCellsMethod · 0.95

Calls 15

LowerCaseMethod · 0.95
ReadMethod · 0.95
DecodeStringMethod · 0.95
PeekMethod · 0.95
ReadLineMethod · 0.95
ReadInformationMethod · 0.95
strdupFunction · 0.85
vtkReadBinaryDataFunction · 0.85
vtkReadASCIIDataFunction · 0.85
ToCharMethod · 0.80
ToSignedCharMethod · 0.80
ToUnsignedCharMethod · 0.80

Tested by

no test coverage detected