本文整理汇总了C++中MDoubleArray::length方法的典型用法代码示例。如果您正苦于以下问题:C++ MDoubleArray::length方法的具体用法?C++ MDoubleArray::length怎么用?C++ MDoubleArray::length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MDoubleArray
的用法示例。
在下文中一共展示了MDoubleArray::length方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: apply
void dynExprField::apply(
MDataBlock &block,
int receptorSize,
const MDoubleArray &magnitudeArray,
const MDoubleArray &magnitudeOwnerArray,
const MVectorArray &directionArray,
const MVectorArray &directionOwnerArray,
MVectorArray &outputForce
)
//
// Compute output force for each particle. If there exists the
// corresponding per particle attribute, use the data passed from
// particle shape (stored in magnitudeArray and directionArray).
// Otherwise, use the attribute value from the field.
//
{
// get the default values
MVector defaultDir = direction(block);
double defaultMag = magnitude(block);
int magArraySize = magnitudeArray.length();
int dirArraySize = directionArray.length();
int magOwnerArraySize = magnitudeOwnerArray.length();
int dirOwnerArraySize = directionOwnerArray.length();
int numOfOwner = magOwnerArraySize;
if( dirOwnerArraySize > numOfOwner )
numOfOwner = dirOwnerArraySize;
double magnitude = defaultMag;
MVector direction = defaultDir;
for (int ptIndex = 0; ptIndex < receptorSize; ptIndex ++ ) {
if(receptorSize == magArraySize)
magnitude = magnitudeArray[ptIndex];
if(receptorSize == dirArraySize)
direction = directionArray[ptIndex];
if( numOfOwner > 0) {
for( int nthOwner = 0; nthOwner < numOfOwner; nthOwner++ ) {
if(magOwnerArraySize == numOfOwner)
magnitude = magnitudeOwnerArray[nthOwner];
if(dirOwnerArraySize == numOfOwner)
direction = directionOwnerArray[nthOwner];
outputForce.append( direction * magnitude );
}
} else {
outputForce.append( direction * magnitude );
}
}
}
示例2: dData
bool
PxrUsdMayaWriteUtil::ReadMayaAttribute(
const MFnDependencyNode& depNode,
const MString& name,
VtFloatArray* val)
{
MStatus status;
depNode.attribute(name, &status);
if (status == MS::kSuccess) {
MPlug plug = depNode.findPlug(name);
MObject dataObj;
if ( (plug.getValue(dataObj) == MS::kSuccess) &&
(dataObj.hasFn(MFn::kDoubleArrayData)) ) {
MFnDoubleArrayData dData(dataObj, &status);
if (status == MS::kSuccess) {
MDoubleArray arrayValues = dData.array();
size_t numValues = arrayValues.length();
val->resize(numValues);
for (size_t i = 0; i < numValues; ++i) {
(*val)[i] = arrayValues[i];
}
return true;
}
}
}
return false;
}
示例3: assert
// Reference: OSD shape_utils.h:: applyTags() "crease"
static float
getCreaseEdges(MFnMesh const & inMeshFn, Descriptor & outDesc) {
MUintArray tEdgeIds;
MDoubleArray tCreaseData;
float maxCreaseValue = 0.0f;
if (inMeshFn.getCreaseEdges(tEdgeIds, tCreaseData)) {
assert( tEdgeIds.length() == tCreaseData.length() );
int ncreases = tEdgeIds.length();
int * vertPairs = new int[ncreases*2];
float * weights = new float[ncreases];
int2 edgeVerts;
for (unsigned int j=0; j < tEdgeIds.length(); j++) {
assert( tCreaseData[j] >= 0.0 );
inMeshFn.getEdgeVertices(tEdgeIds[j], edgeVerts);
vertPairs[j*2 ] = edgeVerts[0];
vertPairs[j*2+1] = edgeVerts[1];
weights[j] = float(tCreaseData[j]);
maxCreaseValue = std::max(float(tCreaseData[j]), maxCreaseValue);
}
outDesc.numCreases = ncreases;
outDesc.creaseVertexIndexPairs = vertPairs;
outDesc.creaseWeights = weights;
}
return maxCreaseValue;
}
示例4: assert
// Reference: OSD shape_utils.h:: applyTags() "corner"
float
applyCreaseVertices( MFnMesh const & inMeshFn, HMesh * hbrMesh ) {
MUintArray tVertexIds;
MDoubleArray tCreaseData;
float maxCreaseValue = 0.0f;
if ( inMeshFn.getCreaseVertices(tVertexIds, tCreaseData) ) {
assert( tVertexIds.length() == tCreaseData.length() );
// Has crease vertices
for (unsigned int j=0; j < tVertexIds.length(); j++) {
// Assumption: The OSD vert ids are identical to those of the Maya mesh
HVertex * v = hbrMesh->GetVertex( tVertexIds[j] );
if(v) {
assert( tCreaseData[j] >= 0.0 );
v->SetSharpness( (float)tCreaseData[j] );
maxCreaseValue = std::max(float(tCreaseData[j]), maxCreaseValue);
} else {
fprintf(stderr,
"warning: cannot find vertex for corner tag (%d)\n",
tVertexIds[j] );
}
}
}
return maxCreaseValue;
}
示例5: useOgawa
AlembicWriteJob::AlembicWriteJob(const MString &in_FileName,
const MObjectArray &in_Selection,
const MDoubleArray &in_Frames, bool use_ogawa,
const std::vector<std::string> &in_prefixFilters,
const std::set<std::string> &in_attributes,
const std::vector<std::string> &in_userPrefixFilters,
const std::set<std::string> &in_userAttributes)
: useOgawa(use_ogawa),
mPrefixFilters(in_prefixFilters),
mAttributes(in_attributes),
mUserPrefixFilters(in_userPrefixFilters),
mUserAttributes(in_userAttributes)
{
// ensure to clear the isRefAnimated cache
clearIsRefAnimatedCache();
mFileName = in_FileName;
for (unsigned int i = 0; i < in_Selection.length(); i++) {
mSelection.append(in_Selection[i]);
}
for (unsigned int i = 0; i < in_Frames.length(); i++) {
mFrames.push_back(in_Frames[i]);
}
}
示例6: doItQuery
void skinClusterWeights::doItQuery()
{
MStatus status;
unsigned int i, j;
MDoubleArray weights;
// To allow "skinClusterWeights -q" to return empty double array
setResult(weights);
MSelectionList selList;
for (i = 0; i < geometryArray.length(); i++) {
MDagPath dagPath;
MObject component;
selList.clear();
selList.add(geometryArray[i]);
MStatus status = selList.getDagPath(0, dagPath, component);
if (status != MS::kSuccess) {
continue;
}
if (component.isNull()) dagPath.extendToShape();
MObject skinCluster = findSkinCluster(dagPath);
if (!isSkinClusterIncluded(skinCluster)) {
continue;
}
MFnSkinCluster skinClusterFn(skinCluster, &status);
if (status != MS::kSuccess) {
continue;
}
MIntArray influenceIndexArray;
populateInfluenceIndexArray(skinClusterFn, influenceIndexArray);
weights.clear();
skinClusterFn.getWeights(dagPath, component, influenceIndexArray, weights);
if (weights.length() > 0) {
for (j = 0; j < weights.length(); j++) {
appendToResult(weights[j]);
}
}
}
}
示例7: writeXmlValue
MStatus
XmlCacheFormat::writeDoubleArray( const MDoubleArray& array )
{
int size = array.length();
assert(size != 0);
writeXmlTagValue(sizeTag,size);
startXmlBlock( doubleArrayTag );
for(int i = 0; i < size; i++)
{
writeXmlValue(array[i]);
}
endXmlBlock();
return MS::kSuccess;
}
示例8: doIt
MStatus mDblSignedToUnsigned::doIt( const MArgList& args )
{
// get the arguments
MDoubleArray dblA;
unsigned int count;
MStatus stat = getArgDbl(args, dblA, count);
ERROR_FAIL(stat);
// do the actual job
for (unsigned int i=0;i<dblA.length();i++)
{
dblA[i] = (0.5 * dblA[i] + 0.5);
}
setResult(dblA);
return MS::kSuccess;
}
示例9: getArgDbl
MStatus mDbl1dNoise::doIt( const MArgList& args )
{
// get the arguments
MDoubleArray dblA;
unsigned int count;
MStatus stat = getArgDbl(args, dblA, count);
ERROR_FAIL(stat);
// do the actual job
Noise noiseGen;
for (unsigned int i=0;i<dblA.length();i++)
{
dblA[i] = noiseGen.improvedPerlin1dS(float(dblA[i]));
}
setResult(dblA);
return MS::kSuccess;
}
示例10: GetValidUp
void GetValidUp(const MDoubleArray& weights, const MPointArray& points,
const MIntArray& sampleIds, const MPoint& origin, const MVector& normal,
MVector& up) {
MVector unitUp = up.normal();
// Adjust up if it's parallel to normal or if it's zero length
if (std::abs((unitUp * normal) - 1.0) < 0.001 || up.length() < 0.0001) {
for (unsigned int j = 0; j < weights.length()-1; ++j) {
up -= (points[sampleIds[j]] - origin) * weights[j];
unitUp = up.normal();
if (std::abs((unitUp * normal) - 1.0) > 0.001 && up.length() > 0.0001) {
// If the up and normal vectors are no longer parallel and the up vector has a length,
// then we are good to go.
break;
}
}
up.normalize();
} else {
up = unitUp;
}
}
示例11: compute
MStatus ReduceArrayNode::compute(const MPlug& plug, MDataBlock& data)
{
if (plug != aOutput)
return MS::kUnknownParameter;
MStatus status;
MDataHandle inputHandle = data.inputValue(aInput, &status);
CHECK_MSTATUS_AND_RETURN_IT(status);
MFnDoubleArrayData inputArrayData(inputHandle.data());
MDoubleArray inputArray = inputArrayData.array();
int numInputs = inputArray.length();
short operation = data.inputValue(aOperation).asShort();
double output = numInputs > 0 ? inputArray[0] : 0.0;
if (operation == kLENGTH)
{
output = double(numInputs);
} else {
for (int i = 1; i < numInputs; i++)
{
output = computeOutput(output, inputArray[i], operation, status);
if (!status)
{
reportComputeError(this, operation);
break;
}
}
}
MDataHandle outputHandle = data.outputValue(this->aOutput);
outputHandle.setDouble(output);
outputHandle.setClean();
return MS::kSuccess;
}
示例12: CalculateSampleWeights
void CalculateSampleWeights(const std::map<int, double>& distances, double radius,
MIntArray& vertexIds, MDoubleArray& weights) {
std::map<int, double>::const_iterator itDistance;
std::vector<std::pair<int, double> > samples;
for (itDistance = distances.begin();
itDistance != distances.end();
itDistance++) {
double x = itDistance->second;
double w = 1.0 - (x/radius);
samples.push_back(std::pair<int, double>(itDistance->first, w));
}
// Make the samples a multiple of 4 so we can use fast intrinsics!
int remainder = 4 - ((samples.size()-1) % 4);
if (remainder != 4) {
for (int i = 0; i < remainder; ++i) {
samples.push_back(std::pair<int, double>(0, 0.0));
}
}
unsigned int length = (unsigned int)samples.size();
weights.setLength(length);
vertexIds.setLength(length);
std::sort(samples.begin(), samples.end(), SampleSort);
std::vector<std::pair<int, double> >::iterator iter;
int ii = 0;
double sum = 0.0;
for (iter = samples.begin(); iter != samples.end(); ++iter, ++ii) {
vertexIds[ii] = (*iter).first;
weights[ii] = (*iter).second;
sum += (*iter).second;
}
assert(sum > 0.0);
// Normalize the weights
for (unsigned int i = 0; i < weights.length(); ++i) {
weights[i] /= sum;
}
}
示例13: deform
MStatus PushDeformer::deform(MDataBlock& dataBlock,
MItGeometry& itGeo,
const MMatrix& localToWorldMatrix,
unsigned int geomIndex)
{
MStatus status;
//get attribute handles
double bulgeAmount = dataBlock.inputValue(aAmount, &status).asDouble();
CHECK_MSTATUS_AND_RETURN_IT(status);
m_taskData.envelope = dataBlock.inputValue(envelope, &status).asFloat();
CHECK_MSTATUS_AND_RETURN_IT(status);
bool useStressV = dataBlock.inputValue(aUseStress, &status).asBool();
CHECK_MSTATUS_AND_RETURN_IT(status);
int multiThreadingType = dataBlock.inputValue(aMultiThreadingType, &status).asBool();
CHECK_MSTATUS_AND_RETURN_IT(status);
if (m_taskData.envelope <= 0.001)
{
return MS::kSuccess;
}
// if the use stress plug is turned on pull
MDoubleArray stressV;
if (useStressV == true)
{
//pull out the raw data as an Mobject
MObject stressMap = dataBlock.inputValue(aStressMap, &status).data();
CHECK_MSTATUS_AND_RETURN_IT(status);
MFnDoubleArrayData stressDataFn(stressMap);
m_taskData.stressV = stressDataFn.array();
}
//retrieve the handle to the output array attribute
MArrayDataHandle hInput = dataBlock.outputArrayValue(input, &status);
CHECK_MSTATUS_AND_RETURN_IT(status);
//get the input array index handle
status = hInput.jumpToElement(geomIndex);
//get the handle of geomIndex attribute
MDataHandle hInputElement = hInput.outputValue(&status);
CHECK_MSTATUS_AND_RETURN_IT(status);
//Get the MObject of the input geometry of geomindex
MObject oInputGeom = hInputElement.child(inputGeom).asMesh();
MFnMesh fnMesh(oInputGeom, &status);
CHECK_MSTATUS_AND_RETURN_IT(status);
fnMesh.getVertexNormals(false, m_taskData.normals, MSpace::kWorld);
itGeo.allPositions(m_taskData.points, MSpace::kWorld);
//MGlobal::displayInfo( "test" );
/*for (int i = 0; i < itGeo.count(); i++)
{
MGlobal::displayInfo( MFnAttribute(weightList).isArray );
}*/
m_taskData.bulgeAmount = bulgeAmount;
if(multiThreadingType == 1)
{
ThreadData* pThreadData = createThreadData( NUM_TASKS, &m_taskData );
MThreadPool::newParallelRegion( createTasks, (void*)pThreadData );
itGeo.setAllPositions(m_taskData.points);
delete [] pThreadData;
return MS::kSuccess;
}
else if(multiThreadingType == 2)
{
tbb::parallel_for(size_t(0), size_t(itGeo.count()), [this](size_t i)
{
//const float w = weightValue(dataBlock, geomIndex, i);
const float w = 1.0;
if (m_taskData.useStressV == true && (m_taskData.stressV.length() > 0))
{
//deform
m_taskData.points[i] += (MVector(m_taskData.normals[i]) * m_taskData.bulgeAmount * m_taskData.envelope * w * m_taskData.stressV[i]);
}
else
{
//deform
m_taskData.points[i] += m_taskData.normals[i] * m_taskData.bulgeAmount * m_taskData.envelope * w;
}
});
}
//
else if(multiThreadingType == 3)
#pragma omp parallel for
for (int i = 0; i < itGeo.count(); i++)
{
float w = weightValue(dataBlock, geomIndex, itGeo.index());
if (useStressV == true && (stressV.length() > 0))
{
//deform
m_taskData.points[i] += (MVector(m_taskData.normals[i]) * bulgeAmount * m_taskData.envelope * w * m_taskData.stressV[i]);
}
else
{
//.........这里部分代码省略.........
示例14: CalculateBasisComponents
void CalculateBasisComponents(const MDoubleArray& weights, const BaryCoords& coords,
const MIntArray& triangleVertices, const MPointArray& points,
const MFloatVectorArray& normals, const MIntArray& sampleIds,
double* alignedStorage,
MPoint& origin, MVector& up, MVector& normal) {
// Start with the recreated point and normal using the barycentric coordinates of the hit point.
unsigned int hitIndex = weights.length()-1;
#ifdef __AVX__
__m256d originV = Dot4<MPoint>(coords[0], coords[1], coords[2], 0.0,
points[triangleVertices[0]], points[triangleVertices[1]],
points[triangleVertices[2]], MPoint::origin);
__m256d hitNormalV = Dot4<MVector>(coords[0], coords[1], coords[2], 0.0,
normals[triangleVertices[0]], normals[triangleVertices[1]],
normals[triangleVertices[2]], MVector::zero);
__m256d hitWeightV = _mm256_set1_pd(weights[hitIndex]);
// Create the barycentric point and normal.
__m256d normalV = _mm256_mul_pd(hitNormalV, hitWeightV);
// Then use the weighted adjacent data.
for (unsigned int j = 0; j < hitIndex; j += 4) {
__m256d tempNormal = Dot4<MVector>(weights[j], weights[j+1], weights[j+2], weights[j+3],
normals[sampleIds[j]], normals[sampleIds[j+1]],
normals[sampleIds[j+2]], normals[sampleIds[j+3]]);
normalV = _mm256_add_pd(tempNormal, normalV);
}
_mm256_store_pd(alignedStorage, originV);
origin.x = alignedStorage[0];
origin.y = alignedStorage[1];
origin.z = alignedStorage[2];
_mm256_store_pd(alignedStorage, normalV);
normal.x = alignedStorage[0];
normal.y = alignedStorage[1];
normal.z = alignedStorage[2];
// Calculate the up vector
const MPoint& pt1 = points[triangleVertices[0]];
const MPoint& pt2 = points[triangleVertices[1]];
__m256d p1 = _mm256_set_pd(pt1.w, pt1.z, pt1.y, pt1.x);
__m256d p2 = _mm256_set_pd(pt2.w, pt2.z, pt2.y, pt2.x);
p1 = _mm256_add_pd(p1, p2);
__m256d half = _mm256_set_pd(0.5, 0.5, 0.5, 0.5);
p1 = _mm256_mul_pd(p1, half);
__m256d upV = _mm256_sub_pd(p1, originV);
_mm256_store_pd(alignedStorage, upV);
up.x = alignedStorage[0];
up.y = alignedStorage[1];
up.z = alignedStorage[2];
#else
MVector hitNormal;
// Create the barycentric point and normal.
for (int i = 0; i < 3; ++i) {
origin += points[triangleVertices[i]] * coords[i];
hitNormal += MVector(normals[triangleVertices[i]]) * coords[i];
}
// Use crawl data to calculate normal
normal = hitNormal * weights[hitIndex];
for (unsigned int j = 0; j < hitIndex; j++) {
normal += MVector(normals[sampleIds[j]]) * weights[j];
}
// Calculate the up vector
// The triangle vertices are sorted by decreasing barycentric coordinates so the first two are
// the two closest vertices in the triangle.
up = ((points[triangleVertices[0]] + points[triangleVertices[1]]) * 0.5) - origin;
#endif
normal.normalize();
GetValidUp(weights, points, sampleIds, origin, normal, up);
}
示例15: meshFn
void
OsdPtexMeshData::rebuildHbrMeshIfNeeded(OpenSubdivPtexShader *shader)
{
MStatus status;
if (!_meshTopoDirty && !shader->getHbrMeshDirty())
return;
MFnMesh meshFn(_meshDagPath, &status);
if (status != MS::kSuccess) return;
int level = shader->getLevel();
if (level < 1) level =1;
SchemeType scheme = shader->getScheme();
if (scheme == kLoop) scheme = kCatmark; // XXX: avoid loop for now
// Get Maya vertex topology and crease data
MIntArray vertexCount;
MIntArray vertexList;
meshFn.getVertices(vertexCount, vertexList);
MUintArray edgeIds;
MDoubleArray edgeCreaseData;
meshFn.getCreaseEdges(edgeIds, edgeCreaseData);
MUintArray vtxIds;
MDoubleArray vtxCreaseData;
meshFn.getCreaseVertices(vtxIds, vtxCreaseData);
if (vertexCount.length() == 0) return;
// Cache attribute values
_level = shader->getLevel();
_scheme = shader->getScheme();
_kernel = shader->getKernel();
_adaptive = shader->isAdaptive();
_interpBoundary = shader->getInterpolateBoundary();
// Copy Maya vectors into std::vectors
std::vector<int> numIndices(&vertexCount[0], &vertexCount[vertexCount.length()]);
std::vector<int> faceIndices(&vertexList[0], &vertexList[vertexList.length()]);
std::vector<int> vtxCreaseIndices(&vtxIds[0], &vtxIds[vtxIds.length()]);
std::vector<double> vtxCreases(&vtxCreaseData[0], &vtxCreaseData[vtxCreaseData.length()]);
std::vector<double> edgeCreases(&edgeCreaseData[0], &edgeCreaseData[edgeCreaseData.length()]);
// Edge crease index is stored as pairs of vertex ids
int nEdgeIds = edgeIds.length();
std::vector<int> edgeCreaseIndices;
edgeCreaseIndices.resize(nEdgeIds*2);
for (int i = 0; i < nEdgeIds; ++i) {
int2 vertices;
status = meshFn.getEdgeVertices(edgeIds[i], vertices);
if (status.error()) {
status.perror("ERROR can't get creased edge vertices");
continue;
}
edgeCreaseIndices[i*2] = vertices[0];
edgeCreaseIndices[i*2+1] = vertices[1];
}
// Convert attribute enums to HBR enums (this is why the enums need to match)
// XXX use some sort of built-in transmorgification avoid assumption?
HbrMeshUtil::SchemeType hbrScheme = (HbrMeshUtil::SchemeType) _scheme;
OsdHbrMesh::InterpolateBoundaryMethod hbrInterpBoundary =
(OsdHbrMesh::InterpolateBoundaryMethod) _interpBoundary;
// Convert Maya mesh to internal HBR representation
_hbrmesh = ConvertToHBR(meshFn.numVertices(), numIndices, faceIndices,
vtxCreaseIndices, vtxCreases,
std::vector<int>(), std::vector<float>(),
edgeCreaseIndices, edgeCreases,
hbrInterpBoundary,
hbrScheme,
true ); // add ptex indices to HBR
// note: GL function can't be used in prepareForDraw API.
_needsInitializeMesh = true;
// Mesh topology data is up to date
_meshTopoDirty = false;
shader->setHbrMeshDirty(false);
}