void __TestReorderCopy() { size_t numTuples = 10; QVector<size_t> cDims(1, 5); QString name("Source Array"); //make sure that an incorrectly sized order returns a null pointer typename DataArray<T>::Pointer src = DataArray<T>::CreateArray(numTuples, cDims, name, false); QVector<size_t> wrongSize(numTuples + 1); typename DataArray<T>::Pointer copy = boost::dynamic_pointer_cast<DataArray<T> >(src->reorderCopy(wrongSize)); DREAM3D_REQUIRE_EQUAL(copy.get(), 0); // fill reorder vector with same index (using this would be the same result as deep copy) QVector<size_t> newOrder(numTuples); for(size_t i = 0; i < numTuples; i++) { newOrder[i] = i; } //shuffle order std::random_shuffle(newOrder.begin(), newOrder.end()); // First lets try it without allocating any memory copy = boost::dynamic_pointer_cast<DataArray<T> >(src->reorderCopy(newOrder)); //if newOrder is inporperly size a null pointer is returned DREAM3D_REQUIRE_NE(copy.get(), 0); //check sizes DREAM3D_REQUIRED(copy->getNumberOfTuples(), ==, src->getNumberOfTuples() ); DREAM3D_REQUIRED(copy->isAllocated(), ==, src->isAllocated() ); // Create the array again, this time allocating the data and putting in some known data src = DataArray<T>::CreateArray(numTuples, cDims, name, true); for(size_t i = 0; i < src->getSize(); i++) { src->setValue(i, i); } for(size_t i = 0; i < numTuples; i++) { for(size_t j = 0; j < cDims[0]; j++) { src->setComponent(i, j, static_cast<T>(i * cDims[0] + j) ); } } copy = boost::dynamic_pointer_cast<DataArray<T> >(src->reorderCopy(newOrder)); for(size_t i = 0; i < numTuples; i++) { for(size_t j = 0; j < cDims[0]; j++) { T cpy = copy->getComponent(newOrder[i], j); T val = src->getComponent(i, j); DREAM3D_REQUIRE_EQUAL(cpy, val) } } }
int32_t readDataChunk(AttributeMatrix::Pointer attrMat, std::istream& in, bool inPreflight, bool binary, const QString& scalarName, int32_t scalarNumComp) { size_t numTuples = attrMat->getNumTuples(); QVector<size_t> tDims = attrMat->getTupleDimensions(); QVector<size_t> cDims(1, scalarNumComp); typename DataArray<T>::Pointer data = DataArray<T>::CreateArray(tDims, cDims, scalarName, !inPreflight); data->initializeWithZeros(); attrMat->addAttributeArray(data->getName(), data); if (inPreflight == true) { return skipVolume<T>(in, binary, numTuples * scalarNumComp); } else { if (binary) { int32_t err = vtkReadBinaryData<T>(in, data->getPointer(0), numTuples, scalarNumComp); if( err < 0 ) { std::cout << "Error Reading Binary Data '" << scalarName.toStdString() << "' " << attrMat->getName().toStdString() << " numTuples = " << numTuples << std::endl; return err; } if(BIGENDIAN == 0) {data->byteSwapElements(); } } else { T value = static_cast<T>(0.0); size_t totalSize = numTuples * scalarNumComp; for (size_t i = 0; i < totalSize; ++i) { in >> value; data->setValue(i, value); } } } return 0; }
int __ValidateArray(typename DataArray<T>::Pointer array, size_t numTuples, int numComp) { int err = 0; DREAM3D_REQUIRED(true, ==, array->isAllocated() ); size_t nt = array->getNumberOfTuples(); DREAM3D_REQUIRED(nt, ==, numTuples); int nc = array->getNumberOfComponents(); DREAM3D_REQUIRED(nc, ==, numComp ); size_t typeSize = array->getTypeSize(); DREAM3D_REQUIRE_EQUAL(sizeof(T), typeSize); size_t numElements = array->getSize(); DREAM3D_REQUIRED(numElements, ==, (nt * nc) ); // initialize the array with zeros to get a baseline array->initializeWithZeros(); // Get a pointer to the data and loop through the array making sure all values are Zero T* ptr = array->getPointer(0); for(size_t i = 0; i < numElements; i++) { DREAM3D_REQUIRE_EQUAL(0, ptr[i]); } //Splat another value across the array starting at an offset into the array //and test those values made it into the array correctly array->initializeWithValue(static_cast<T>(1), numComp); for(size_t i = numComp; i < numElements; i++) { DREAM3D_REQUIRE_EQUAL(static_cast<T>(1), ptr[i]); } // Initialize the entire array with a value (offset = 0); array->initializeWithValue(static_cast<T>(2), 0); for(size_t i = 0; i < numElements; i++) { DREAM3D_REQUIRE_EQUAL(static_cast<T>(2), ptr[i]); } // Initialize the entire array with a value (offset = 0), this time using the default value for the offset array->initializeWithValue(static_cast<T>(3)); ptr = array->getPointer(0); for(size_t i = 0; i < numElements; i++) { DREAM3D_REQUIRE_EQUAL(static_cast<T>(3), ptr[i]); array->setValue(i, static_cast<T>(4)); T val = array->getValue(i); DREAM3D_REQUIRE_EQUAL(val, static_cast<T>(4)) } // Test setting of a Tuple with a value, which means all components of that tuple will have the same value size_t index = 0; array->initializeWithZeros(); for(size_t t = 0; t < numTuples; t++) { array->initializeTuple(t, 6.0); for(int j = 0; j < numComp; j++) { T val = array->getComponent(t, j); DREAM3D_REQUIRE_EQUAL(val, (static_cast<T>(6)) ) } } // Test setting individual components to a specific value index = 0; array->initializeWithZeros(); for(size_t t = 0; t < numTuples; t++) { for(int j = 0; j < numComp; j++) { index = t * numComp + j; array->setComponent(t, j, static_cast<T>(t + j) ); T val = array->getComponent(t, j); DREAM3D_REQUIRE_EQUAL(val, (static_cast<T>(t + j))) val = array->getValue(index); DREAM3D_REQUIRE_EQUAL(val, (static_cast<T>(t + j))) } } /// virtual QVector<size_t> getComponentDimensions() // Test resizing the array based on a give number of tuples. The number of Components will stay the same at each tuple array->resize(numTuples * 2); array->initializeWithZeros(); // Init the grown array to all Zeros nt = array->getNumberOfTuples(); DREAM3D_REQUIRED(nt, ==, (numTuples * 2) ); nc = array->getNumberOfComponents(); DREAM3D_REQUIRED(nc, ==, numComp ); // Test resizing the array to a smaller size array->resize(numTuples); array->initializeWithZeros(); // Init the grown array to all Zeros nt = array->getNumberOfTuples(); DREAM3D_REQUIRED(nt, ==, (numTuples) ); nc = array->getNumberOfComponents(); DREAM3D_REQUIRED(nc, ==, numComp ); ////clear() // This resizes the array to Zero destroying all the data in the process. array->clear(); DREAM3D_REQUIRED(false, ==, array->isAllocated() ); nt = array->getNumberOfTuples(); DREAM3D_REQUIRED(nt, ==, 0); nc = array->getNumberOfComponents(); DREAM3D_REQUIRED(nc, ==, numComp); nt = array->getSize(); DREAM3D_REQUIRED(nt, ==, 0); ptr = array->getPointer(0); DREAM3D_REQUIRED_PTR(ptr, ==, NULL); // Test resizing the array to a any larger size array->resize(numTuples); array->initializeWithZeros(); // Init the grown array to all Zeros nt = array->getNumberOfTuples(); DREAM3D_REQUIRED(nt, ==, (numTuples) ); nc = array->getNumberOfComponents(); DREAM3D_REQUIRED(nc, ==, numComp ); ptr = array->getPointer(0); DREAM3D_REQUIRED_PTR(ptr, !=, NULL); return err; }