------------------------------------------------------------------------------ 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.
| 1541 | // the data object and then invoke Delete() it to restore proper reference |
| 1542 | // count. |
| 1543 | vtkAbstractArray* 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 | { |
no test coverage detected