本文整理汇总了C++中idataarray::Pointer::initializeTuple方法的典型用法代码示例。如果您正苦于以下问题:C++ Pointer::initializeTuple方法的具体用法?C++ Pointer::initializeTuple怎么用?C++ Pointer::initializeTuple使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类idataarray::Pointer
的用法示例。
在下文中一共展示了Pointer::initializeTuple方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: initializeArrayWithReals
void InitializeData::initializeArrayWithReals(IDataArray::Pointer p, int64_t dims[3])
{
T rangeMin;
T rangeMax;
if (m_InitType == RandomWithRange)
{
rangeMin = static_cast<T>(m_InitRange.first);
rangeMax = static_cast<T>(m_InitRange.second);
}
else
{
rangeMin = std::numeric_limits<T>().min();
rangeMax = std::numeric_limits<T>().max();
}
typedef boost::mt19937 RandomNumberGenerator;
typedef boost::uniform_real<T> RealDistribution;
typedef boost::variate_generator<RandomNumberGenerator&, RealDistribution> RealGenerator;
std::shared_ptr<RealDistribution> distribution = std::shared_ptr<RealDistribution>(new RealDistribution(rangeMin, rangeMax));
std::shared_ptr<RandomNumberGenerator> randomNumberGenerator = std::shared_ptr<RandomNumberGenerator>(new RandomNumberGenerator);
randomNumberGenerator->seed(static_cast<size_t>(QDateTime::currentMSecsSinceEpoch())); // seed with the current time
std::shared_ptr<RealGenerator> realGeneratorPtr = std::shared_ptr<RealGenerator>(new RealGenerator(*randomNumberGenerator, *distribution));
RealGenerator& realGenerator = *realGeneratorPtr;
for (int32_t k = m_ZMin; k < m_ZMax + 1; k++)
{
for (int32_t j = m_YMin; j < m_YMax + 1; j++)
{
for (int32_t i = m_XMin; i < m_XMax + 1; i++)
{
size_t index = (k * dims[0] * dims[1]) + (j * dims[0]) + i;
if (m_InitType == Manual)
{
T num = static_cast<T>(m_InitValue);
p->initializeTuple(index, &num);
}
else
{
T temp = realGenerator();
p->initializeTuple(index, &temp);
}
}
}
}
}
示例2: add_noise
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void AddBadData::add_noise()
{
notifyStatusMessage(getHumanLabel(), "Adding Noise");
DREAM3D_RANDOMNG_NEW()
DataContainer::Pointer m = getDataContainerArray()->getDataContainer(getGBEuclideanDistancesArrayPath().getDataContainerName());
QString attMatName = getGBEuclideanDistancesArrayPath().getAttributeMatrixName();
QList<QString> voxelArrayNames = m->getAttributeMatrix(attMatName)->getAttributeArrayNames();
float random = 0.0f;
size_t totalPoints = m->getGeometryAs<ImageGeom>()->getNumberOfElements();
for (size_t i = 0; i < totalPoints; ++i)
{
if (m_BoundaryNoise == true && m_GBEuclideanDistances[i] < 1)
{
random = static_cast<float>( rg.genrand_res53() );
if (random < m_BoundaryVolFraction)
{
for (QList<QString>::iterator iter = voxelArrayNames.begin(); iter != voxelArrayNames.end(); ++iter)
{
IDataArray::Pointer p = m->getAttributeMatrix(attMatName)->getAttributeArray(*iter);
p->initializeTuple(i, 0);
}
}
}
if (m_PoissonNoise == true)
{
random = static_cast<float>( rg.genrand_res53() );
if (random < m_PoissonVolFraction)
{
for (QList<QString>::iterator iter = voxelArrayNames.begin(); iter != voxelArrayNames.end(); ++iter)
{
IDataArray::Pointer p = m->getAttributeMatrix(attMatName)->getAttributeArray(*iter);
p->initializeTuple(i, 0);
}
}
}
}
}
示例3: execute
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void InitializeData::execute()
{
setErrorCondition(0);
dataCheck();
if(getErrorCondition() < 0) { return; }
DataContainer::Pointer m = getDataContainerArray()->getDataContainer(m_CellAttributeMatrixPath.getDataContainerName());
size_t udims[3] =
{ 0, 0, 0 };
m->getGeometryAs<ImageGeom>()->getDimensions(udims);
#if (CMP_SIZEOF_SIZE_T == 4)
typedef int32_t DimType;
#else
typedef int64_t DimType;
#endif
DimType dims[3] =
{ static_cast<DimType>(udims[0]), static_cast<DimType>(udims[1]), static_cast<DimType>(udims[2]), };
int index;
QString attrMatName = m_CellAttributeMatrixPath.getAttributeMatrixName();
QList<QString> voxelArrayNames = m->getAttributeMatrix(attrMatName)->getAttributeArrayNames();
for (int32_t k = m_ZMin; k < m_ZMax + 1; k++)
{
for (int32_t j = m_YMin; j < m_YMax + 1; j++)
{
for (int32_t i = m_XMin; i < m_XMax + 1; i++)
{
index = (k * dims[0] * dims[1]) + (j * dims[0]) + i;
for (QList<QString>::iterator iter = voxelArrayNames.begin(); iter != voxelArrayNames.end(); ++iter)
{
IDataArray::Pointer p = m->getAttributeMatrix(attrMatName)->getAttributeArray(*iter);
p->initializeTuple(index, 0);
}
}
}
}
notifyStatusMessage(getHumanLabel(), "Complete");
}
示例4: execute
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void WarpRegularGrid::execute()
{
setErrorCondition(0);
dataCheck();
if(getErrorCondition() < 0) { return; }
DataContainer::Pointer m;
if (m_SaveAsNewDataContainer == false) { m = getDataContainerArray()->getDataContainer(getCellAttributeMatrixPath().getDataContainerName()); }
else { m = getDataContainerArray()->getDataContainer(getNewDataContainerName()); }
AttributeMatrix::Pointer cellAttrMat = m->getAttributeMatrix(getCellAttributeMatrixPath().getAttributeMatrixName());
AttributeMatrix::Pointer newCellAttrMat = cellAttrMat->deepCopy();
size_t dims[3] = { 0, 0, 0 };
m->getGeometryAs<ImageGeom>()->getDimensions(dims);
float res[3] = { 0.0f, 0.0f, 0.0f };
m->getGeometryAs<ImageGeom>()->getResolution(res);
size_t totalPoints = m->getGeometryAs<ImageGeom>()->getNumberOfElements();
float x = 0.0f, y = 0.0f, z = 0.0f;
float newX = 0.0f, newY = 0.0f;
int col = 0.0f, row = 0.0f, plane = 0.0f;
size_t index;
size_t index_old;
std::vector<size_t> newindicies(totalPoints);
std::vector<bool> goodPoint(totalPoints, true);
for (size_t i = 0; i < dims[2]; i++)
{
QString ss = QObject::tr("Warping Data - %1 Percent Complete").arg(((float)i / dims[2]) * 100);
notifyStatusMessage(getMessagePrefix(), getHumanLabel(), ss);
for (size_t j = 0; j < dims[1]; j++)
{
for (size_t k = 0; k < dims[0]; k++)
{
x = static_cast<float>((k * res[0]));
y = static_cast<float>((j * res[1]));
z = static_cast<float>((i * res[2]));
index = (i * dims[0] * dims[1]) + (j * dims[0]) + k;
determine_warped_coordinates(x, y, newX, newY);
col = newX / res[0];
row = newY / res[1];
plane = i;
index_old = (plane * dims[0] * dims[1]) + (row * dims[0]) + col;
newindicies[index] = index_old;
if (col > 0 && col < dims[0] && row > 0 && row < dims[1]) { goodPoint[index] = true; }
else { goodPoint[index] = false; }
}
}
}
QList<QString> voxelArrayNames = cellAttrMat->getAttributeArrayNames();
for (QList<QString>::iterator iter = voxelArrayNames.begin(); iter != voxelArrayNames.end(); ++iter)
{
IDataArray::Pointer p = cellAttrMat->getAttributeArray(*iter);
// Make a copy of the 'p' array that has the same name. When placed into
// the data container this will over write the current array with
// the same name. At least in theory
IDataArray::Pointer data = p->createNewArray(p->getNumberOfTuples(), p->getComponentDimensions(), p->getName());
data->resize(totalPoints);
void* source = NULL;
void* destination = NULL;
size_t newIndicies_I = 0;
int nComp = data->getNumberOfComponents();
for (size_t i = 0; i < static_cast<size_t>(totalPoints); i++)
{
newIndicies_I = newindicies[i];
if(goodPoint[i] == true)
{
source = p->getVoidPointer((nComp * newIndicies_I));
destination = data->getVoidPointer((data->getNumberOfComponents() * i));
::memcpy(destination, source, p->getTypeSize() * data->getNumberOfComponents());
}
else
{
int var = 0;
data->initializeTuple(i, &var);
}
}
cellAttrMat->removeAttributeArray(*iter);
newCellAttrMat->addAttributeArray(*iter, data);
}
m->removeAttributeMatrix(getCellAttributeMatrixPath().getAttributeMatrixName());
m->addAttributeMatrix(getCellAttributeMatrixPath().getAttributeMatrixName(), newCellAttrMat);
notifyStatusMessage(getHumanLabel(), "Complete");
}
示例5: execute
//.........这里部分代码省略.........
if (fabs(GeometryMath::CosThetaBetweenVectors(zAxis, xAxisNew)) > closestAxis) { xResNew = zRes, closestAxis = fabs(GeometryMath::CosThetaBetweenVectors(zAxis, xAxisNew)); }
yResNew = yRes;
closestAxis = fabs(GeometryMath::CosThetaBetweenVectors(yAxis, yAxisNew));
if (fabs(GeometryMath::CosThetaBetweenVectors(xAxis, yAxisNew)) > closestAxis) { yResNew = xRes, closestAxis = fabs(GeometryMath::CosThetaBetweenVectors(xAxis, yAxisNew)); }
if (fabs(GeometryMath::CosThetaBetweenVectors(zAxis, yAxisNew)) > closestAxis) { yResNew = zRes, closestAxis = fabs(GeometryMath::CosThetaBetweenVectors(zAxis, yAxisNew)); }
zResNew = zRes;
closestAxis = fabs(GeometryMath::CosThetaBetweenVectors(zAxis, zAxisNew));
if (fabs(GeometryMath::CosThetaBetweenVectors(xAxis, zAxisNew)) > closestAxis) { zResNew = xRes, closestAxis = fabs(GeometryMath::CosThetaBetweenVectors(xAxis, zAxisNew)); }
if (fabs(GeometryMath::CosThetaBetweenVectors(yAxis, zAxisNew)) > closestAxis) { zResNew = yRes, closestAxis = fabs(GeometryMath::CosThetaBetweenVectors(yAxis, zAxisNew)); }
xpNew = static_cast<int64_t>(nearbyint((xMax - xMin) / xResNew) + 1);
ypNew = static_cast<int64_t>(nearbyint((yMax - yMin) / yResNew) + 1);
zpNew = static_cast<int64_t>(nearbyint((zMax - zMin) / zResNew) + 1);
params.xpNew = xpNew;
params.xResNew = xResNew;
params.xMinNew = xMin;
params.ypNew = ypNew;
params.yResNew = yResNew;
params.yMinNew = yMin;
params.zpNew = zpNew;
params.zResNew = zResNew;
params.zMinNew = zMin;
int64_t newNumCellTuples = params.xpNew * params.ypNew * params.zpNew;
DataArray<int64_t>::Pointer newIndiciesPtr = DataArray<int64_t>::CreateArray(newNumCellTuples, "_INTERNAL_USE_ONLY_RotateSampleRef_NewIndicies");
newIndiciesPtr->initializeWithValue(-1);
int64_t* newindicies = newIndiciesPtr->getPointer(0);
#ifdef SIMPLib_USE_PARALLEL_ALGORITHMS
tbb::task_scheduler_init init;
bool doParallel = true;
#endif
#ifdef SIMPLib_USE_PARALLEL_ALGORITHMS
if (doParallel == true)
{
tbb::parallel_for(tbb::blocked_range3d<int64_t, int64_t, int64_t>(0, params.zpNew, 0, params.ypNew, 0, params.xpNew),
RotateSampleRefFrameImpl(newIndiciesPtr, ¶ms, rotMat, m_SliceBySlice), tbb::auto_partitioner());
}
else
#endif
{
RotateSampleRefFrameImpl serial(newIndiciesPtr, ¶ms, rotMat, m_SliceBySlice);
serial.convert(0, params.zpNew, 0, params.ypNew, 0, params.xpNew);
}
// This could technically be parallelized also where each thread takes an array to adjust. Except
// that the DataContainer is NOT thread safe or re-entrant so that would actually be a BAD idea.
QString attrMatName = getCellAttributeMatrixPath().getAttributeMatrixName();
QList<QString> voxelArrayNames = m->getAttributeMatrix(attrMatName)->getAttributeArrayNames();
// resize attribute matrix
QVector<size_t> tDims(3);
tDims[0] = params.xpNew;
tDims[1] = params.ypNew;
tDims[2] = params.zpNew;
m->getAttributeMatrix(attrMatName)->resizeAttributeArrays(tDims);
for (QList<QString>::iterator iter = voxelArrayNames.begin(); iter != voxelArrayNames.end(); ++iter)
{
IDataArray::Pointer p = m->getAttributeMatrix(attrMatName)->getAttributeArray(*iter);
// Make a copy of the 'p' array that has the same name. When placed into
// the data container this will over write the current array with
// the same name.
IDataArray::Pointer data = p->createNewArray(newNumCellTuples, p->getComponentDimensions(), p->getName());
void* source = NULL;
void* destination = NULL;
int64_t newIndicies_I = 0;
int32_t nComp = data->getNumberOfComponents();
for (size_t i = 0; i < static_cast<size_t>(newNumCellTuples); i++)
{
newIndicies_I = newindicies[i];
if(newIndicies_I >= 0)
{
source = p->getVoidPointer((nComp * newIndicies_I));
if (NULL == source)
{
QString ss = QObject::tr("The index is outside the bounds of the source array");
setErrorCondition(-11004);
notifyErrorMessage(getHumanLabel(), ss, getErrorCondition());
return;
}
destination = data->getVoidPointer((data->getNumberOfComponents() * i));
::memcpy(destination, source, p->getTypeSize() * data->getNumberOfComponents());
}
else
{
data->initializeTuple(i, 0);
}
}
m->getAttributeMatrix(attrMatName)->addAttributeArray(*iter, data);
}
m->getGeometryAs<ImageGeom>()->setResolution(params.xResNew, params.yResNew, params.zResNew);
m->getGeometryAs<ImageGeom>()->setDimensions(params.xpNew, params.ypNew, params.zpNew);
m->getGeometryAs<ImageGeom>()->setOrigin(xMin, yMin, zMin);
notifyStatusMessage(getHumanLabel(), "Complete");
}
示例6: execute
//.........这里部分代码省略.........
/**fit x and y shifts to lines
*
* y = mx + b
*
* m = (n*sum(x_i * y_i) - sum(x_i) * sum(y_i)) / (n*sum(x_i^2)-sum(x_i)^2
*
* b = (sum(y_i)-m*sum(x_i))/n
*
*/
// same for both
double sumX = 0.0; // sum(x_i)
double sumX_2 = 0.0; // sum(x_i^2)
// x shift line
double x_sumY = 0.0; // sum(y_i)
double x_sumXY = 0.0; // sum(x_i * y_i)
// y shift line
double y_sumY = 0.0; // sum(y_i)
double y_sumXY = 0.0; // sum(x_i * y_i)
for (DimType iter = 0; iter < dims[2]; iter++)
{
slice = static_cast<DimType>( (dims[2] - 1) - iter );
sumX = static_cast<double>(sumX + iter);
sumX_2 = static_cast<double>(sumX_2 + iter * iter);
x_sumY = static_cast<double>(x_sumY + xshifts[iter]);
x_sumXY = static_cast<double>(x_sumXY + iter * xshifts[iter]);
y_sumY = static_cast<double>(y_sumY + yshifts[iter]);
y_sumXY = static_cast<double>(y_sumXY + iter * yshifts[iter]);
}
double mx = static_cast<double>((dims[2] * x_sumXY - x_sumXY) / (dims[2] * sumX_2 - sumX));
double my = static_cast<double>((dims[2] * y_sumXY - y_sumXY) / (dims[2] * sumX_2 - sumX));
// adjust shifts so that fit line has 0 slope (~ends of the sample are fixed)
for (DimType iter = 1; iter < dims[2]; iter++)
{
slice = (dims[2] - 1) - iter;
xshifts[iter] = static_cast<int64_t>(xshifts[iter] - iter * mx);
yshifts[iter] = static_cast<int64_t>(yshifts[iter] - iter * my);
}
}
QList<QString> voxelArrayNames = m->getAttributeMatrix(getCellAttributeMatrixName())->getAttributeArrayNames();
DimType progIncrement = dims[2] / 100;
DimType prog = 1;
DimType progressInt = 0;
for (DimType i = 1; i < dims[2]; i++)
{
if (i > prog)
{
progressInt = ((float)i / dims[2]) * 100.0f;
QString ss = QObject::tr("Transferring Cell Data || %1% Complete").arg(progressInt);
notifyStatusMessage(getMessagePrefix(), getHumanLabel(), ss);
prog = prog + progIncrement;
}
if (getCancel() == true)
{
return;
}
slice = (dims[2] - 1) - i;
for (DimType l = 0; l < dims[1]; l++)
{
for (DimType n = 0; n < dims[0]; n++)
{
if (yshifts[i] >= 0) { yspot = l; }
else if (yshifts[i] < 0) { yspot = dims[1] - 1 - l; }
if (xshifts[i] >= 0) { xspot = n; }
else if (xshifts[i] < 0) { xspot = dims[0] - 1 - n; }
newPosition = (slice * dims[0] * dims[1]) + (yspot * dims[0]) + xspot;
currentPosition = (slice * dims[0] * dims[1]) + ((yspot + yshifts[i]) * dims[0]) + (xspot + xshifts[i]);
if ((yspot + yshifts[i]) >= 0 && (yspot + yshifts[i]) <= dims[1] - 1 && (xspot + xshifts[i]) >= 0
&& (xspot + xshifts[i]) <= dims[0] - 1)
{
for (QList<QString>::iterator iter = voxelArrayNames.begin(); iter != voxelArrayNames.end(); ++iter)
{
IDataArray::Pointer p = m->getAttributeMatrix(getCellAttributeMatrixName())->getAttributeArray(*iter);
p->copyTuple(currentPosition, newPosition);
}
}
if ((yspot + yshifts[i]) < 0 || (yspot + yshifts[i]) > dims[1] - 1 || (xspot + xshifts[i]) < 0
|| (xspot + xshifts[i]) > dims[0] - 1)
{
for (QList<QString>::iterator iter = voxelArrayNames.begin(); iter != voxelArrayNames.end(); ++iter)
{
IDataArray::Pointer p = m->getAttributeMatrix(getCellAttributeMatrixName())->getAttributeArray(*iter);
p->initializeTuple(newPosition, 0);
}
}
}
}
}
// If there is an error set this to something negative and also set a message
notifyStatusMessage(getHumanLabel(), "Complete");
}