本文整理汇总了C++中MFloatArray类的典型用法代码示例。如果您正苦于以下问题:C++ MFloatArray类的具体用法?C++ MFloatArray怎么用?C++ MFloatArray使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MFloatArray类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _GetLightingParam
static
bool
_GetLightingParam(
const MIntArray& intValues,
const MFloatArray& floatValues,
GfVec4f& paramValue)
{
bool gotParamValue = false;
if (intValues.length() >= 3) {
paramValue[0] = intValues[0];
paramValue[1] = intValues[1];
paramValue[2] = intValues[2];
if (intValues.length() > 3) {
paramValue[3] = intValues[3];
}
gotParamValue = true;
} else if (floatValues.length() >= 3) {
paramValue[0] = floatValues[0];
paramValue[1] = floatValues[1];
paramValue[2] = floatValues[2];
if (floatValues.length() > 3) {
paramValue[3] = floatValues[3];
}
gotParamValue = true;
}
return gotParamValue;
}
示例2: polyIt
// #### buildUVList
//
// Face-varying data expects a list of per-face per-vertex
// floats. This method reads the UVs from the mesh and
// concatenates them into such a list.
//
MStatus
OsdMeshData::buildUVList( MFnMesh& meshFn, std::vector<float>& uvList )
{
MStatus status = MS::kSuccess;
MItMeshPolygon polyIt( _meshDagPath );
MFloatArray uArray;
MFloatArray vArray;
// If user hasn't given us a UV set, use the current one
MString *uvSetPtr=NULL;
if ( _uvSet.numChars() > 0 ) {
if (uvSetNameIsValid(meshFn, _uvSet)) {
uvSetPtr = &_uvSet;
}
else {
MGlobal::displayWarning(MString("OpenSubdivShader: uvSet \""+_uvSet+"\" does not exist."));
}
} else {
uvSetPtr = NULL;
}
// pull UVs from Maya mesh
status = meshFn.getUVs( uArray, vArray, uvSetPtr );
MCHECK_RETURN(status, "OpenSubdivShader: Error reading UVs");
if ( uArray.length() == 0 || vArray.length() == 0 )
{
MGlobal::displayWarning("OpenSubdivShader: Mesh has no UVs");
return MS::kFailure;
}
// list of UV values
uvList.clear();
uvList.resize( meshFn.numFaceVertices()*2 );
int uvListIdx = 0;
// for each face-vertex copy UVs into list, adjusting for renderman orientation
for ( polyIt.reset(); !polyIt.isDone(); polyIt.next() )
{
int faceIdx = polyIt.index();
unsigned int numPolyVerts = polyIt.polygonVertexCount();
for ( unsigned int faceVertIdx = 0;
faceVertIdx < numPolyVerts;
faceVertIdx++ )
{
int uvIdx;
polyIt.getUVIndex( faceVertIdx, uvIdx, uvSetPtr );
// convert maya UV orientation to renderman orientation
uvList[ uvListIdx++ ] = uArray[ uvIdx ];
uvList[ uvListIdx++ ] = 1.0f - vArray[ uvIdx ];
}
}
return status;
}
示例3: checkCrossingEdges
unsigned int peltOverlap::checkCrossingEdges(
MFloatArray &face1Orig,
MFloatArray &face1Vec,
MFloatArray &face2Orig,
MFloatArray &face2Vec
)
// Check if there are crossing edges between two faces. Return true
// if there are crossing edges and false otherwise. A face is represented
// by a series of edges(rays), i.e.
// faceOrig[] = {orig1u, orig1v, orig2u, orig2v, ... }
// faceVec[] = {vec1u, vec1v, vec2u, vec2v, ... }
{
unsigned int face1Size = face1Orig.length();
unsigned int face2Size = face2Orig.length();
for (unsigned int i = 0; i < face1Size; i += 2) {
float o1x = face1Orig[i];
float o1y = face1Orig[i+1];
float v1x = face1Vec[i];
float v1y = face1Vec[i+1];
float n1x = v1y;
float n1y = -v1x;
for (unsigned int j = 0; j < face2Size; j += 2) {
// Given ray1(O1, V1) and ray2(O2, V2)
// Normal of ray1 is (V1.y, V1.x)
float o2x = face2Orig[j];
float o2y = face2Orig[j+1];
float v2x = face2Vec[j];
float v2y = face2Vec[j+1];
float n2x = v2y;
float n2y = -v2x;
// Find t for ray2
// t = [(o1x-o2x)n1x + (o1y-o2y)n1y] / (v2x * n1x + v2y * n1y)
float denum = v2x * n1x + v2y * n1y;
// Edges are parallel if denum is close to 0.
if (fabs(denum) < 0.000001f) continue;
float t2 = ((o1x-o2x)* n1x + (o1y-o2y) * n1y) / denum;
if (t2 < 0.00001f || t2 > 0.99999f) continue;
// Find t for ray1
// t = [(o2x-o1x)n2x + (o2y-o1y)n2y] / (v1x * n2x + v1y * n2y)
denum = v1x * n2x + v1y * n2y;
// Edges are parallel if denum is close to 0.
if (fabs(denum) < 0.000001f) continue;
float t1 = ((o2x-o1x)* n2x + (o2y-o1y) * n2y) / denum;
// Edges intersect
if (t1 > 0.00001f && t1 < 0.99999f) return 1;
}
}
return 0;
}
示例4: rng
// We try to do some image processing on a normal rgb image before finding the contours.
// An example when this could be useful is if we want to separate all bricks in a brick wall.
// We can do this by using the texture of the brick wall as input.
// However it doesnt work that well :(
MStatus SplitFromImage::splitFromRGBImage(MFnMesh &mesh, MString image) {
cout << "Image filename: " << image.asChar() << endl;
// Load image
cv::Mat img, imgGray;
img = cv::imread(image.asChar(), CV_LOAD_IMAGE_COLOR);
if (!img.data) // Check for invalid input
{
cout << "Could not open or find the image" << endl;
return MS::kFailure;
}
int thresh = 100;
int max_thresh = 255;
cv::RNG rng(12345);
// Convert image to gray and blur it
cv::cvtColor(img, imgGray, CV_BGR2GRAY);
cv::blur(imgGray, imgGray, cv::Size(3, 3));
cv::Mat canny_output;
std::vector<std::vector<cv::Point> > contours;
std::vector<cv::Vec4i> hierarchy;
// Detect edges using canny
cv::Canny(imgGray, canny_output, thresh, thresh * 2, 3);
// Find contours
cv::findContours(img, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, cv::Point(0, 0));
for (int i = 0; i < contours.size(); i++) {
MFloatArray uPoints;
MFloatArray vPoints;
for (int j = 0; j < contours[i].size(); j++) {
cv::Point pt = contours[i][j];
float u = (float)pt.x / img.cols;
float v = (float)pt.y / img.rows;
uPoints.append(u);
vPoints.append(v);
}
MObject newMesh;
if (addPlaneSubMesh(newMesh, uPoints, vPoints, mesh) == MS::kSuccess)
cout << "Added plane sub mesh!" << endl;
else
cout << "Couldn't add plane sub mesh!" << endl;
}
return MS::kSuccess;
}
示例5: createCircleUvs
void ropeGenerator::createCircleUvs( int pointsCount, float uvCapSize, MFloatArray &uArray, MFloatArray &vArray, float direction)
{
MPoint baseVector( 0.5 * uvCapSize,0,0 );
uArray.append( baseVector.x + 0.5 );
vArray.append( baseVector.z + 0.5 );
for ( int d = 1; d < pointsCount; d++ )
{
MVector vVector( baseVector );
vVector = vVector.rotateBy( MVector::kYaxis,
MAngle(( 360.0 * direction / float( pointsCount )) * float( d ),MAngle::kDegrees).asRadians() );
uArray.append( vVector.x + 0.5 );
vArray.append( vVector.z + 0.5 );
}
}
示例6: copy_patch_uvs
// uScale and vScale switched because first edge pointing in v direction
void copy_patch_uvs(int &kV, int &kHE, MFloatArray &u_src, MFloatArray &v_src, MIntArray &uvIdx_src, MFloatArray &u_dst, MFloatArray &v_dst, float vScale, float uScale, MFloatArray &sc_u_dst, MFloatArray &sc_v_dst, MIntArray &uvIdx_dst, float lineThickness)
{
int nHE = uvIdx_src.length();
for (int k=0; k<nHE; k++)
{
uvIdx_dst[kHE] = kV + uvIdx_src[k]; // offset by beginning of this block of UVs
kHE++;
}
// float offset_u = (uScale - 1) * 0.5*lineThickness;
// float offset_v = (vScale - 1) * 0.5*lineThickness;
lineThickness = 0.5 * lineThickness;
float offset_u = lineThickness * (uScale - 1.0)/(uScale - 2*lineThickness);
float offset_v = lineThickness * (vScale - 1.0)/(vScale - 2*lineThickness);
int nV = u_src.length();
for (int k=0; k<nV; k++)
{
u_dst[kV] = u_src[k] * (1.0 - 2.0*offset_u) + offset_u;
v_dst[kV] = v_src[k] * (1.0 - 2.0*offset_v) + offset_v;
sc_u_dst[kV] = uScale * u_src[k];
sc_v_dst[kV] = vScale * v_src[k];
kV++;
}
}
示例7: create_subdivided_face
void create_subdivided_face(int sdRes, int nV, double *uvs, double *itv, int Tidx, MFloatArray &uA, MFloatArray &vA, MIntArray &uvIdx)
{
HDS hds;
hds.V.setDims(2, nV); memcpy(&hds.V.v[0], uvs, 2*nV*sizeof(double));
hds.nFV.setDims(1, 1); hds.nFV[0] = nV;
hds.tip.setDims(1, nV);
for (size_t k=0; k<nV; k++)
{
hds.tip[k] = k;
}
finalize_HDS(hds);
size_t nHE = hds.nHE(), nIHE = hds.nIHE();⟵
hds.T.setDims(1, nHE);
hds.itv.setDims(1, nHE);
memset(&hds.T.v[0], 0, nHE*sizeof(bool)); if (nV==5) hds.T[Tidx] = 1;
memcpy(&hds.itv.v[0], itv, nV*sizeof(double));
// border halfedge tags
for (size_t k=nIHE; k<nHE; k++)
{
hds.itv[k] = hds.itv[hds.twin[k]];
}
TCC_MAX::linear_subdivide(hds, sdRes);
int sd_nV = hds.nV();
int sd_nIHE = hds.nIHE();
uA.setLength(sd_nV);
vA.setLength(sd_nV);
for (int k=0; k<sd_nV; k++)
{
uA[k] = hds.V[2*k+0];
vA[k] = hds.V[2*k+1];
}
uvIdx.setLength(sd_nIHE);
for (int k=0; k<sd_nIHE; k++)
{
uvIdx[k]=hds.tip[k];
}
}
示例8: iter
void peltOverlap::createBoundingCircle(const MStringArray &flattenFaces, MFloatArray ¢er, MFloatArray &radius)
//
// Description
// Represent a face by a center and radius, i.e.
// center = {center1u, center1v, center2u, center2v, ... }
// radius = {radius1, radius2, ... }
//
{
center.setLength(2 * flattenFaces.length());
radius.setLength(flattenFaces.length());
for(unsigned int i = 0; i < flattenFaces.length(); i++) {
MSelectionList selList;
selList.add(flattenFaces[i]);
MDagPath dagPath;
MObject comp;
selList.getDagPath(0, dagPath, comp);
MItMeshPolygon iter(dagPath, comp);
MFloatArray uArray, vArray;
iter.getUVs(uArray, vArray);
// Loop through all vertices to construct edges/rays
float cu = 0.f;
float cv = 0.f;
unsigned int j;
for(j = 0; j < uArray.length(); j++) {
cu += uArray[j];
cv += vArray[j];
}
cu = cu / uArray.length();
cv = cv / vArray.length();
float rsqr = 0.f;
for(j = 0; j < uArray.length(); j++) {
float du = uArray[j] - cu;
float dv = vArray[j] - cv;
float dsqr = du*du + dv*dv;
rsqr = dsqr > rsqr ? dsqr : rsqr;
}
center[2*i] = cu;
center[2*i+1] = cv;
radius[i] = sqrt(rsqr);
}
}
示例9: createRopesUvs
void ropeGenerator::createRopesUvs( int ropesCount, int pointsCount, float ropeStrength, float uvCapSize,MFloatArray &uArray, MFloatArray &vArray, float direction )
{
MAngle angle( (180.0/ ropesCount ), MAngle::kDegrees );
float distanceToMoveRope = cos( angle.asRadians() );
float singleRopeRadius = sin( angle.asRadians() );
float baseAngle = 360.0f / float( ropesCount );
for ( int d = 1; d < ropesCount + 1; d++)
{
MFloatPointArray ropePoints( createHalfRope( pointsCount, singleRopeRadius ) );
for ( int ropP = 0; ropP < ropePoints.length(); ropP++)
{
MFloatPoint ropPoint( ropePoints[ropP] );
MVector ropV( ropPoint.x, ropPoint.y, ropPoint.z * ropeStrength );
ropV = ropV + MVector( 0,0,-distanceToMoveRope );
ropV = ropV.rotateBy( MVector::kYaxis, MAngle( baseAngle * float( d ), MAngle::kDegrees).asRadians() );
ropV = ropV * 0.5 * uvCapSize;
uArray.append( (( ropV.x * direction) + 0.5 ) );
vArray.append( ropV.z + 0.5 );
}
}
}
示例10: splitFromBinaryImage
MStatus SplitFromImage::splitFromBinaryImage(MFnMesh &mesh, MString image) {
cout << "Image filename: " << image.asChar() << endl;
// Load image
cv::Mat img;
img = cv::imread(image.asChar(), CV_LOAD_IMAGE_GRAYSCALE);
if (!img.data) // Check for invalid input
{
cout << "Could not open or find the image" << endl;
return MS::kFailure;
}
std::vector<std::vector<cv::Point> > contours;
std::vector<cv::Vec4i> hierarchy;
// Find contours
cv::findContours(img, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, cv::Point(0, 0));
for (int i = 0; i < contours.size(); i++) {
MFloatArray uPoints;
MFloatArray vPoints;
for (int j = 0; j < contours[i].size(); j++) {
cv::Point pt = contours[i][j];
float u = (float)pt.x / img.cols;
float v = (float)pt.y / img.rows;
uPoints.append(u);
vPoints.append(v);
}
MObject newMesh;
if (addPlaneSubMesh(newMesh, uPoints, vPoints, mesh) == MS::kSuccess)
cout << "Added plane sub mesh!" << endl;
else
cout << "Couldn't add plane sub mesh!" << endl;
}
return MS::kSuccess;
}
示例11: area
float peltOverlap::area(const MFloatArray &orig)
{
float sum = 0.f;
unsigned int num = orig.length() / 2;
for (unsigned int i = 0; i < num; i++) {
unsigned int idx = 2 * i;
unsigned int idy = (i + 1 ) % num;
idy = 2 * idy + 1;
unsigned int idy2 = (i + num - 1) % num;
idy2 = 2 * idy2 + 1;
sum += orig[idx] * (orig[idy] - orig[idy2]);
}
return fabs(sum) * 0.5f;
}
示例12:
MStatus
XmlCacheFormat::readFloatArray( MFloatArray& array, unsigned arraySize )
{
MStringArray value;
readXmlTagValue(floatArrayTag, value);
assert( value.length() == arraySize );
array.setLength( arraySize );
for ( unsigned int i = 0; i < value.length(); i++ )
{
array[i] = (float)strtod( value[i].asChar(), NULL );
}
return MS::kSuccess;
}
示例13: writeXmlValue
MStatus
XmlCacheFormat::writeFloatArray( const MFloatArray& array )
{
int size = array.length();
assert(size != 0);
writeXmlTagValue(sizeTag,size);
startXmlBlock( floatArrayTag );
for(int i = 0; i < size; i++)
{
writeXmlValue(array[i]);
}
endXmlBlock();
return MS::kSuccess;
}
示例14: sourceFnMesh
MStatus TransferUV::redoIt()
{
MStatus status;
MFnMesh sourceFnMesh(sourceDagPath);
MFnMesh targetFnMesh(targetDagPath);
// Get current UV sets and keep them to switch back to them at the last
MString currentSourceUVSet = sourceFnMesh.currentUVSetName();
MString currentTargetUVSet = targetFnMesh.currentUVSetName();
// Switch to uv sets specified in flags before starting transfer process
// This is required because MFnMesh does not work properly with
// "Non-current" UV sets
sourceFnMesh.setCurrentUVSetName(sourceUvSet);
targetFnMesh.setCurrentUVSetName(targetUvSet);
MString* sourceUvSetPtr = &sourceUvSet;
MString* targetUvSetPtr = &targetUvSet;
MFloatArray sourceUarray;
MFloatArray sourceVarray;
MIntArray sourceUvCounts;
MIntArray sourceUvIds;
// Get mesh information for each
status = sourceFnMesh.getUVs(sourceUarray, sourceVarray, sourceUvSetPtr);
if (status != MS::kSuccess) {
MGlobal::displayError("Failed to get source UVs");
CHECK_MSTATUS_AND_RETURN_IT(status);
}
status = targetFnMesh.getUVs(originalUarray, originalVarray, targetUvSetPtr);
if (status != MS::kSuccess) {
MGlobal::displayError("Failed to get original UVs");
CHECK_MSTATUS_AND_RETURN_IT(status);
}
status = sourceFnMesh.getAssignedUVs(sourceUvCounts, sourceUvIds, sourceUvSetPtr);
if (status != MS::kSuccess) {
MGlobal::displayError("Failed to get source assigned UVs");
CHECK_MSTATUS_AND_RETURN_IT(status);
}
status = targetFnMesh.getAssignedUVs(originalUvCounts, originalUvIds, targetUvSetPtr);
if (status != MS::kSuccess) {
MGlobal::displayError("Failed to get original assigned UVs");
CHECK_MSTATUS_AND_RETURN_IT(status);
}
// Resize source uv array so it becomes same size as number of targets uv
unsigned int targetNumUVs = targetFnMesh.numUVs();
if (targetNumUVs > sourceUarray.length()) {
sourceUarray.setLength(targetNumUVs);
sourceVarray.setLength(targetNumUVs);
}
status = targetFnMesh.setUVs(sourceUarray, sourceVarray, targetUvSetPtr);
if (MS::kSuccess != status) {
MGlobal::displayError("Failed to set source UVs");
return status;
}
status = targetFnMesh.assignUVs(sourceUvCounts, sourceUvIds, targetUvSetPtr);
if (MS::kSuccess != status) {
MGlobal::displayError("Failed to assign source UVs");
return status;
}
// Switch back to originals
sourceFnMesh.setCurrentUVSetName(currentSourceUVSet);
targetFnMesh.setCurrentUVSetName(currentTargetUVSet);
return MS::kSuccess;
}
示例15: interpolation
void ToMayaMeshConverter::addUVSet( MFnMesh &fnMesh, const MIntArray &polygonCounts, IECore::ConstMeshPrimitivePtr mesh, const std::string &sPrimVarName, const std::string &tPrimVarName, const std::string &stIdPrimVarName, MString *uvSetName ) const
{
IECore::PrimitiveVariableMap::const_iterator sIt = mesh->variables.find( sPrimVarName );
bool haveS = sIt != mesh->variables.end();
IECore::PrimitiveVariableMap::const_iterator tIt = mesh->variables.find( tPrimVarName );
bool haveT = tIt != mesh->variables.end();
IECore::PrimitiveVariableMap::const_iterator stIdIt = mesh->variables.find( stIdPrimVarName );
bool haveSTId = stIdIt != mesh->variables.end();
if ( haveS && haveT )
{
if ( sIt->second.interpolation != IECore::PrimitiveVariable::FaceVarying )
{
IECore::msg( IECore::Msg::Warning,"ToMayaMeshConverter::doConversion", boost::format( "PrimitiveVariable \"%s\" has unsupported interpolation (expected FaceVarying).") % sPrimVarName );
return;
}
if ( tIt->second.interpolation != IECore::PrimitiveVariable::FaceVarying )
{
IECore::msg( IECore::Msg::Warning, "ToMayaMeshConverter::doConversion", boost::format( "PrimitiveVariable \"%s\" has unsupported interpolation (expected FaceVarying).") % tPrimVarName);
return;
}
if ( !sIt->second.data )
{
IECore::msg( IECore::Msg::Warning, "ToMayaMeshConverter::doConversion", boost::format( "PrimitiveVariable \"%s\" has no data." ) % sPrimVarName );
}
if ( !tIt->second.data )
{
IECore::msg( IECore::Msg::Warning, "ToMayaMeshConverter::doConversion", boost::format( "PrimitiveVariable \"%s\" has no data." ) % tPrimVarName );
}
/// \todo Employ some M*Array converters to simplify this
int numUVs = mesh->variableSize( IECore::PrimitiveVariable::FaceVarying );
IECore::ConstFloatVectorDataPtr u = IECore::runTimeCast<const IECore::FloatVectorData>(sIt->second.data);
if ( !u )
{
IECore::msg( IECore::Msg::Warning, "ToMayaMeshConverter::doConversion", boost::format( "PrimitiveVariable \"%s\" has unsupported type \"%s\"." ) % sPrimVarName % sIt->second.data->typeName() );
return;
}
assert( (int)u->readable().size() == numUVs );
IECore::ConstFloatVectorDataPtr v = IECore::runTimeCast<const IECore::FloatVectorData>(tIt->second.data);
if ( !v )
{
IECore::msg( IECore::Msg::Warning, "ToMayaMeshConverter::doConversion", boost::format( "PrimitiveVariable \"%s\" has unsupported type \"%s\"." ) % tPrimVarName % tIt->second.data->typeName() );
return;
}
assert( (int)v->readable().size() == numUVs );
const std::vector<float> &uAll = u->readable();
const std::vector<float> &vAll = v->readable();
if ( uvSetName )
{
bool setExists = false;
MStringArray existingSets;
fnMesh.getUVSetNames( existingSets );
for ( unsigned i=0; i < existingSets.length(); ++i )
{
if ( *uvSetName == existingSets[i] )
{
fnMesh.clearUVs( uvSetName );
setExists = true;
break;
}
}
if ( !setExists )
{
MDagPath dag;
MStatus s = fnMesh.getPath( dag );
if ( s )
{
fnMesh.createUVSetWithName( *uvSetName );
}
else
{
fnMesh.createUVSetDataMeshWithName( *uvSetName );
}
}
}
MIntArray uvIds;
uvIds.setLength( numUVs );
MFloatArray uArray;
MFloatArray vArray;
if( haveSTId )
{
// Get compressed uv values by matching them with their uvId.
IECore::ConstIntVectorDataPtr uvId = IECore::runTimeCast<const IECore::IntVectorData>(stIdIt->second.data);
if ( !uvId )
{
IECore::msg( IECore::Msg::Warning, "ToMayaMeshConverter::doConversion", boost::format( "PrimitiveVariable \"%s\" has unsupported type \"%s\"." ) % stIdPrimVarName % stIdIt->second.data->typeName() );
//.........这里部分代码省略.........