void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { double *inputWave, *mfcc; int i, frameNum, feaDim; char message[200], cfgFile[200]; if (nrhs<4){ sprintf(message, "Usage: mfcc = %s(y, fs, nbits, cfgFile)", mexFunctionName()); mexErrMsgTxt(message); } /* Assign pointers to the various parameters */ inputWave = mxGetPr(INPUTWAVE); int waveLen= mxGetM(INPUTWAVE)*mxGetN(INPUTWAVE); int fs=(int)mxGetScalar(FS); int nbits=(int)mxGetScalar(NBITS); int status = mxGetString(CFGFILE, cfgFile, 200); if(status != 0) mexWarnMsgTxt("Not enough space. String is truncated."); if (vecMax(inputWave, waveLen)<=1) mexPrintf("Input wave signals are not likely to be integers since all are within the range [-1 1]! Perhaps you should use wavReadInt.m instead?\n"); fstream file; file.open(cfgFile, ios::in); if (!file){ file.close(); sprintf(message, "Cannot open config file %s!", cfgFile); mexErrMsgTxt(message); } int *wave = new int[waveLen]; for (i=0; i<waveLen; i++) wave[i]=inputWave[i]; CMel myMel; myMel.wave2mfcc(wave, fs, nbits, waveLen, cfgFile, &frameNum, &feaDim); float *feature=new float[frameNum*feaDim]; memcpy(feature, myMel.m_feature, frameNum*feaDim*sizeof(float)); delete [] wave; // mexPrintf("fs=%d\n", fs); // mexPrintf("nbits=%d\n", nbits); // mexPrintf("waveLen=%d\n", waveLen); // mexPrintf("cfgFile=%s\n", cfgFile); // mexPrintf("frameNum=%d\n", frameNum); // mexPrintf("feaDim=%d\n", feaDim); // Create output MFCC = mxCreateDoubleMatrix(feaDim, frameNum, mxREAL); mfcc = mxGetPr(MFCC); for (i=0; i<feaDim*frameNum; i++) mfcc[i]=feature[i]; }
void CqTeapot::Bound(CqBound* bound) const { CqVector3D vecMin( -3.000, -2.0, 0.0 ); CqVector3D vecMax( 3.525, 2.0, ( m_CrowBase ? 3.15 : 3.15 - 0.15 /* remove bottom */ ) ); bound->vecMin() = vecMin; bound->vecMax() = vecMax; bound->Transform( m_matTx ); AdjustBoundForTransformationMotion( bound ); }
double NeedleCollisionClearanceCost::value(const vector<double>& x, Model* model) { DblVec dists; EnvironmentBasePtr env = helper->pis[0]->local_configs[0]->GetEnv(); BOOST_FOREACH(const CollisionEvaluatorPtr& cc, this->ccs) { DblVec tmp_dists; cc->CalcDists(x, tmp_dists); for (int i = 0; i < tmp_dists.size(); ++i) { dists.push_back(-tmp_dists[i]); } } if (dists.size() > 0) { return vecMax(dists) * this->coeff; } else { return - helper->collision_clearance_threshold * this->coeff; } }
void Mesh_Bounds(Model *pModel, Vec4 &vecBound) { i32 i; i32 j; Vec3 vecMax(0.f,0.f,0.f); Vec3 vecMin(0.f,0.f,0.f); float *pVert=pModel->p_fVerts; for(j=0;j<pModel->iMeshes;j++) { for(i=0;i<pModel->pMesh[j]->iNumVerts;i++) { if(vecMax.GetX()<pVert[0]) { vecMax.SetX(pVert[0]); } if(vecMax.GetY()<pVert[1]) { vecMax.SetY(pVert[1]); } if(vecMax.GetZ()<pVert[2]) { vecMax.SetZ(pVert[2]); } if(vecMin.GetX()>pVert[0]) { vecMin.SetX(pVert[0]); } if(vecMin.GetY()>pVert[1]) { vecMin.SetY(pVert[1]); } if(vecMin.GetZ()>pVert[2]) { vecMin.SetZ(pVert[2]); } pVert+=3; } } vecBound.SetX(vecMax.GetX()-vecMin.GetX()); vecBound.SetY(vecMax.GetY()-vecMin.GetY()); vecBound.SetZ(vecMax.GetZ()-vecMin.GetZ()); vecBound.SetW(vecBound.Length()/2.f); }
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { double *wave, *ep; int m, n, i, j, fs, waveLen, index1, index2; char message[200]; /* Check for proper number of arguments */ if (nrhs!=2) { strcpy(message, mexFunctionName()); strcat(message, " requires 2 input arguments.\n"); strcat(message, "Usage: ep = "); strcat(message, mexFunctionName()); strcat(message, "(wave, fs)"); mexErrMsgTxt(message); } /* Dimensions of the input matrix */ waveLen = mxGetM(WAVE)*mxGetN(WAVE); /* Create a matrix for the return argument */ EP = mxCreateDoubleMatrix(1, 2, mxREAL); /* Assign pointers to the various parameters */ wave = mxGetPr(WAVE); fs = (int) mxGetScalar(FS); ep = mxGetPr(EP); if (vecMax(wave, waveLen)<=1) mexErrMsgTxt("Input wave signals are not likely to be integers since all are within the range [-1 1]! Perhaps you should use wavReadInt.m instead?"); int *waveInt = (int *)malloc(waveLen*sizeof(int)); double2intVec(wave, waveLen, waveInt); epdByVolHod(waveInt, waveLen, fs, &index1, &index2); free(waveInt); ep[0]=index1+1; // MATLAB index ep[1]=index2+1; // MATLAB index }
//----------------------------------------------------------------------------- // Purpose: // Input : *pPatch - // *pPoints - // &vecNormal - // flArea - //----------------------------------------------------------------------------- bool CVRADDispColl::InitPatch( int iPatch, int iParentPatch, int iChild, Vector *pPoints, int *pIndices, float &flArea ) { // Get the current patch. CPatch *pPatch = &g_Patches[iPatch]; if ( !pPatch ) return false; // Clear the patch data. memset( pPatch, 0, sizeof( CPatch ) ); // Setup the parent if we are not the parent. CPatch *pParentPatch = NULL; if ( iParentPatch != g_Patches.InvalidIndex() ) { // Get the parent patch. pParentPatch = &g_Patches[iParentPatch]; if ( !pParentPatch ) return false; } // Attach the face to the correct lists. if ( !pParentPatch ) { // This is a parent. pPatch->ndxNext = g_FacePatches.Element( GetParentIndex() ); g_FacePatches[GetParentIndex()] = iPatch; pPatch->faceNumber = GetParentIndex(); } else { pPatch->ndxNext = g_Patches.InvalidIndex(); pPatch->faceNumber = pParentPatch->faceNumber; // Attach to the parent patch. if ( iChild == 0 ) { pParentPatch->child1 = iPatch; } else { pParentPatch->child2 = iPatch; } } // Initialize parent and children indices. pPatch->child1 = g_Patches.InvalidIndex(); pPatch->child2 = g_Patches.InvalidIndex(); pPatch->ndxNextClusterChild = g_Patches.InvalidIndex(); pPatch->ndxNextParent = g_Patches.InvalidIndex(); pPatch->parent = iParentPatch; // Get triangle edges. Vector vecEdges[3]; vecEdges[0] = pPoints[1] - pPoints[0]; vecEdges[1] = pPoints[2] - pPoints[0]; vecEdges[2] = pPoints[2] - pPoints[1]; // Find the longest edge. // float flEdgeLength = 0.0f; // for ( int iEdge = 0; iEdge < 3; ++iEdge ) // { // if ( flEdgeLength < vecEdges[iEdge].Length() ) // { // flEdgeLength = vecEdges[iEdge].Length(); // } // } // Calculate the triangle normal and area. Vector vecNormal = vecEdges[1].Cross( vecEdges[0] ); flArea = VectorNormalize( vecNormal ); flArea *= 0.5f; // Initialize the patch scale. pPatch->scale[0] = pPatch->scale[1] = 1.0f; // Set the patch chop - minchop (that is what the minimum area is based on). pPatch->chop = dispchop; // Displacements are not sky! pPatch->sky = false; // Copy the winding. Vector vecCenter( 0.0f, 0.0f, 0.0f ); pPatch->winding = AllocWinding( 3 ); pPatch->winding->numpoints = 3; for ( int iPoint = 0; iPoint < 3; ++iPoint ) { VectorCopy( pPoints[iPoint], pPatch->winding->p[iPoint] ); VectorAdd( pPoints[iPoint], vecCenter, vecCenter ); pPatch->indices[iPoint] = static_cast<short>( pIndices[iPoint] ); } // Set the origin and normal. VectorScale( vecCenter, ( 1.0f / 3.0f ), vecCenter ); VectorCopy( vecCenter, pPatch->origin ); VectorCopy( vecNormal, pPatch->normal ); // Create the plane. pPatch->plane = new dplane_t; if ( !pPatch->plane ) return false; VectorCopy( vecNormal, pPatch->plane->normal ); pPatch->plane->dist = vecNormal.Dot( pPoints[0] ); pPatch->plane->type = PlaneTypeForNormal( pPatch->plane->normal ); pPatch->planeDist = pPatch->plane->dist; // Set the area. pPatch->area = flArea; // Calculate the mins/maxs. Vector vecMin( FLT_MAX, FLT_MAX, FLT_MAX ); Vector vecMax( FLT_MIN, FLT_MIN, FLT_MIN ); for ( int iPoint = 0; iPoint < 3; ++iPoint ) { for ( int iAxis = 0; iAxis < 3; ++iAxis ) { vecMin[iAxis] = MIN( vecMin[iAxis], pPoints[iPoint][iAxis] ); vecMax[iAxis] = MAX( vecMax[iAxis], pPoints[iPoint][iAxis] ); } } VectorCopy( vecMin, pPatch->mins ); VectorCopy( vecMax, pPatch->maxs ); if ( !pParentPatch ) { VectorCopy( vecMin, pPatch->face_mins ); VectorCopy( vecMax, pPatch->face_maxs ); } else { VectorCopy( pParentPatch->face_mins, pPatch->face_mins ); VectorCopy( pParentPatch->face_maxs, pPatch->face_maxs ); } // Check for bumpmap. dface_t *pFace = dfaces + pPatch->faceNumber; texinfo_t *pTexInfo = &texinfo[pFace->texinfo]; pPatch->needsBumpmap = pTexInfo->flags & SURF_BUMPLIGHT ? true : false; // Misc... pPatch->m_IterationKey = 0; // Get the base light for the face. if ( !pParentPatch ) { BaseLightForFace( &g_pFaces[pPatch->faceNumber], pPatch->baselight, &pPatch->basearea, pPatch->reflectivity ); } else { VectorCopy( pParentPatch->baselight, pPatch->baselight ); pPatch->basearea = pParentPatch->basearea; pPatch->reflectivity = pParentPatch->reflectivity; } return true; }
//----------------------------------------------------------------------------- // Purpose: // Input : iPatch - // iParentPatch - // iChild - // *pPoints - // *pIndices - // &flArea - // Output : Returns true on success, false on failure. //----------------------------------------------------------------------------- bool CVRADDispColl::InitParentPatch( int iPatch, Vector *pPoints, float &flArea ) { // Get the current patch. CPatch *pPatch = &g_Patches[iPatch]; if ( !pPatch ) return false; // Clear the patch data. memset( pPatch, 0, sizeof( CPatch ) ); // This is a parent. pPatch->ndxNext = g_FacePatches.Element( GetParentIndex() ); g_FacePatches[GetParentIndex()] = iPatch; pPatch->faceNumber = GetParentIndex(); // Initialize parent and children indices. pPatch->child1 = g_Patches.InvalidIndex(); pPatch->child2 = g_Patches.InvalidIndex(); pPatch->parent = g_Patches.InvalidIndex(); pPatch->ndxNextClusterChild = g_Patches.InvalidIndex(); pPatch->ndxNextParent = g_Patches.InvalidIndex(); Vector vecEdges[2]; vecEdges[0] = pPoints[1] - pPoints[0]; vecEdges[1] = pPoints[3] - pPoints[0]; // Calculate the triangle normal and area. Vector vecNormal = vecEdges[1].Cross( vecEdges[0] ); flArea = VectorNormalize( vecNormal ); // Initialize the patch scale. pPatch->scale[0] = pPatch->scale[1] = 1.0f; // Set the patch chop - minchop (that is what the minimum area is based on). pPatch->chop = dispchop; // Displacements are not sky! pPatch->sky = false; // Copy the winding. Vector vecCenter( 0.0f, 0.0f, 0.0f ); pPatch->winding = AllocWinding( 4 ); pPatch->winding->numpoints = 4; for ( int iPoint = 0; iPoint < 4; ++iPoint ) { VectorCopy( pPoints[iPoint], pPatch->winding->p[iPoint] ); VectorAdd( pPoints[iPoint], vecCenter, vecCenter ); } // Set the origin and normal. VectorScale( vecCenter, ( 1.0f / 4.0f ), vecCenter ); VectorCopy( vecCenter, pPatch->origin ); VectorCopy( vecNormal, pPatch->normal ); // Create the plane. pPatch->plane = new dplane_t; if ( !pPatch->plane ) return false; VectorCopy( vecNormal, pPatch->plane->normal ); pPatch->plane->dist = vecNormal.Dot( pPoints[0] ); pPatch->plane->type = PlaneTypeForNormal( pPatch->plane->normal ); pPatch->planeDist = pPatch->plane->dist; // Set the area. pPatch->area = flArea; // Calculate the mins/maxs. Vector vecMin( FLT_MAX, FLT_MAX, FLT_MAX ); Vector vecMax( FLT_MIN, FLT_MIN, FLT_MIN ); for ( int iPoint = 0; iPoint < 4; ++iPoint ) { for ( int iAxis = 0; iAxis < 3; ++iAxis ) { vecMin[iAxis] = MIN( vecMin[iAxis], pPoints[iPoint][iAxis] ); vecMax[iAxis] = MAX( vecMax[iAxis], pPoints[iPoint][iAxis] ); } } VectorCopy( vecMin, pPatch->mins ); VectorCopy( vecMax, pPatch->maxs ); VectorCopy( vecMin, pPatch->face_mins ); VectorCopy( vecMax, pPatch->face_maxs ); // Check for bumpmap. dface_t *pFace = dfaces + pPatch->faceNumber; texinfo_t *pTexInfo = &texinfo[pFace->texinfo]; pPatch->needsBumpmap = pTexInfo->flags & SURF_BUMPLIGHT ? true : false; // Misc... pPatch->m_IterationKey = 0; // Calculate the base light, area, and reflectivity. BaseLightForFace( &g_pFaces[pPatch->faceNumber], pPatch->baselight, &pPatch->basearea, pPatch->reflectivity ); return true; }
bool PhysicsWorld::Intersects(const StaticPhysicsEntity &s, const DynamicPhysicsEntity &d, Vec &outNormal, Vec &outDir) { float dmin = 0, radiusSquared; Vec min, max, center, scale; min = vec(-1, -1, -1, 0); max = vec(1, 1, 1, 0); scale = vec(1, 1, 1, 0); Mat m, sc; center = entGetTransform(d.ent)->GetPosition(); entGetTransform(s.ent)->GetMatrix(&m); entGetTransform(d.ent)->GetMatrix(&sc); // scale the unit vector and take the largest component // as the radius for the sphere; as long as we don't do // silly rotations we should be ok matMulVec(&scale, sc, scale); radiusSquared = vecMax(scale); radiusSquared *= radiusSquared; // we don't have an inv matrix of anything so instead // we transform everything to worldspace and do the // calculations there // rot + scale matMulVec(&min, m, min); matMulVec(&max, m, max); // pos Vec p = entGetTransform(s.ent)->GetPosition(); min = vecAdd(min, p); max = vecAdd(max, p); // the actual intersection test (don't test w) for(int i = 0; i < 3; i++) { float C = vecGetElem(center, i); float Bmin = vecGetElem(min, i); float Bmax = vecGetElem(max, i); if(C < Bmin) dmin += square(C - Bmin); else if(C > Bmax) dmin += square(C - Bmax); } if(dmin <= radiusSquared) { Ray r; r.o = center; r.d = vecSub(p, center); r.d = vecNormalize(r.d); float dist; bool hit = RayBoxIntersection(r, min, max, dist, outNormal); outDir = vecMul(r.d, vec(dist)); return hit; } return false; }