IDataArray::Pointer copyData(IDataArray::Pointer inputData, size_t totalPoints, int32_t* featureIds) { QString cellArrayName = inputData->getName(); typename DataArray<T>::Pointer feature = std::dynamic_pointer_cast<DataArray<T> >(inputData); if (NULL == feature) { return IDataArray::NullPointer(); } QVector<size_t> cDims = inputData->getComponentDimensions(); typename DataArray<T>::Pointer cell = DataArray<T>::CreateArray(totalPoints, cDims, cellArrayName); T* fPtr = feature->getPointer(0); T* cPtr = cell->getPointer(0); int32_t numComp = feature->getNumberOfComponents(); int32_t featureIdx = 0; for (size_t i = 0; i < totalPoints; ++i) { // Get the feature id (or what ever the user has selected as their "Feature" identifier featureIdx = featureIds[i]; // Now get the pointer to the start of the tuple for the Feature Array at the given Feature Id Index value T* fSourcePtr = fPtr + (numComp * featureIdx); // Now get the pointer to the start of the tuple for the Cell Array at the proper index T* cDestPtr = cPtr + (numComp * i); // Now just raw copy the bytes from the source to the destination ::memcpy(cDestPtr, fSourcePtr, sizeof(T) * numComp); } return cell; }
void reduceArrayOnly(IDataArray::Pointer inputData, IDataArray::Pointer reducedData, int compNumber) { typename DataArray<T>::Pointer inputArrayPtr = boost::dynamic_pointer_cast<DataArray<T> >(inputData); typename DataArray<T>::Pointer reducedArrayPtr = boost::dynamic_pointer_cast<DataArray<T> >(reducedData); if (NULL == inputArrayPtr) { return; } T* inputArray = inputArrayPtr->getPointer(0); T* reducedArray = reducedArrayPtr->getPointer(0); size_t numPoints = inputArrayPtr->getNumberOfTuples(); size_t numComps = inputArrayPtr->getNumberOfComponents(); for (size_t i = 0; i < numPoints; i++) { for (size_t j = 0; j < numComps; j++) { if (j > compNumber) { reducedArray[(numComps - 1)*i + j - 1] = inputArray[numComps * i + j]; } else if (j < compNumber) { reducedArray[(numComps - 1)*i + j] = inputArray[numComps * i + j]; } } } }
void copyData(IDataArray::Pointer fromData, IDataArray::Pointer toData, size_t location) { typename DataArray<T>::Pointer fData = std::dynamic_pointer_cast<DataArray<T>>(fromData); typename DataArray<T>::Pointer tData = std::dynamic_pointer_cast<DataArray<T>>(toData); //only wanting to grab data from tuple 1 to numTuples of the fromData array,s ince the zeroth slot is a placeholder the first AM should already have T* src = fData->getPointer(1 * fromData->getNumberOfComponents()); T* dest = tData->getPointer(location * toData->getNumberOfComponents()); size_t bytes = sizeof(T) * (fromData->getNumberOfTuples() - 1) * fromData->getNumberOfComponents(); ::memcpy(dest, src, bytes); }
void fitData(IDataArray::Pointer inDataPtr, float* ensembleArray, int32_t* eIds, size_t numEnsembles, uint32_t dType, bool removeBiasedFeatures, bool* biasedFeatures) { typename DataArray<T>::Pointer inputDataPtr = std::dynamic_pointer_cast<DataArray<T> >(inDataPtr); StatsData::Pointer sData = StatsData::New(); std::vector<DistributionAnalysisOps::Pointer> distributionAnalysis; distributionAnalysis.push_back(BetaOps::New()); distributionAnalysis.push_back(LogNormalOps::New()); distributionAnalysis.push_back(PowerLawOps::New()); QString distType; int32_t numComp = 1; // Determining number of components and name given distribution type if (dType == SIMPL::DistributionType::Beta) { distType = "Beta", numComp = SIMPL::DistributionType::BetaColumnCount; } else if (dType == SIMPL::DistributionType::LogNormal) { distType = "LogNormal", numComp = SIMPL::DistributionType::LogNormalColumnCount; } else if (dType == SIMPL::DistributionType::Power) { distType = "PowerLaw", numComp = SIMPL::DistributionType::PowerLawColumnCount; } T* fPtr = inputDataPtr->getPointer(0); std::vector<FloatArrayType::Pointer> dist; std::vector<std::vector<float > > values; size_t numfeatures = inputDataPtr->getNumberOfTuples(); dist.resize(numEnsembles); values.resize(numEnsembles); for(size_t i = 1; i < numEnsembles; i++) { dist[i] = sData->CreateDistributionArrays(dType); } int32_t ensemble = 0; for (size_t i = 1; i < numfeatures; i++) { if (removeBiasedFeatures == false || biasedFeatures[i] == false) { ensemble = eIds[i]; values[ensemble].push_back(static_cast<float>(fPtr[i])); } } for (size_t i = 1; i < numEnsembles; i++) { distributionAnalysis[dType]->calculateParameters(values[i], dist[i]); for (int32_t j = 0; j < numComp; j++) { FloatArrayType::Pointer data = dist[i]; ensembleArray[numComp * i + j] = data->getValue(j); } } }
void replaceValue(AbstractFilter* filter, IDataArray::Pointer inDataPtr, BoolArrayType::Pointer condDataPtr, double replaceValue) { typename DataArray<T>::Pointer inputArrayPtr = std::dynamic_pointer_cast<DataArray<T> >(inDataPtr); T replaceVal = static_cast<T>(replaceValue); T* inData = inputArrayPtr->getPointer(0); bool* condData = condDataPtr->getPointer(0); size_t numTuples = inputArrayPtr->getNumberOfTuples(); for (size_t iter = 0; iter < numTuples; iter++) { if (condData[iter] == true) { inData[iter] = replaceVal; } } }
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; }