typename ContactDistanceCalc<BasicTraits,BVOL,Metric>::ResultT ContactDistanceCalc<BasicTraits,BVOL,Metric>::PrimBVolCollision (AdapterType* p0, GroupType* g1) { ++m_numPrimBVolTests; // perform BV-BV overlap test const BVOL& dop1 = p0->getBVol(); const BVOL& dop2 = g1->getBVol(); const Real* center = g1->getData().getRotationCenter(); u32 k, kk, mink, maxk; Real correct; Real min2, max2; for (k=0, kk=BVOL::Size; k<BVOL::Size; ++k, ++kk) { maxk = m_perm[k]; mink = m_perm[kk]; if (maxk < BVOL::Size) { max2 = dop2.maxVector()[maxk] - center[maxk]; min2 = dop2.minVector()[maxk] - center[maxk]; } else { max2 = -dop2.minVector()[mink] + center[mink]; min2 = -dop2.maxVector()[mink] + center[mink]; } min2 *= m_scale; max2 *= m_scale; correct = m_proj[k].dot(g1->getCenter()); #ifdef GV_WITH_SUBCONES min2 = min2*BVOL::unitDopAngleTable(g1->getData().getOccupancy(mink)[m_submask[kk]], m_mask[kk], g1->getData().getOuterMost(mink)[m_submask[kk]]) + correct; max2 = max2*BVOL::unitDopAngleTable(g1->getData().getOccupancy(maxk)[m_submask[k]], m_mask[k], g1->getData().getOuterMost(maxk)[m_submask[k]]) + correct; #else min2 = min2*BVOL::unitDopAngleTable(g1->getData().getOccupancy(mink)[0], m_mask[kk], g1->getData().getOuterMost(mink)[0]) + correct; max2 = max2*BVOL::unitDopAngleTable(g1->getData().getOccupancy(maxk)[0], m_mask[k], g1->getData().getOuterMost(maxk)[0]) + correct; #endif Real value1 = dop1.maxVector()[k] - min2 - m_M1Offset[k]; Real value2 = dop1.minVector()[k] - max2 - m_M1Offset[k]; if (value1 >= 0 && value2 >= 0) { // disjoint case if (value2 > getTolerance()) { return DoubleTraverserBase<BasicTraits>::QUIT; } } else if (value1 < 0 && value2 < 0) { // disjoint case if (-value1 > getTolerance()) { return DoubleTraverserBase<BasicTraits>::QUIT; } } //(value1 >= 0 && value2 < 0), (value1 < 0 && value2 >= 0) is impossible! } return DoubleTraverserBase<BasicTraits>::CONTINUE; }
// ------------------------------------------------------------ void EffectTextureExporter::add3DProjection ( COLLADASW::Texture* colladaTexture, MObject projection ) { int projectionType; DagHelper::getPlugValue ( projection, ATTR_PROJECTION_TYPE, projectionType ); String strProjectionType = ShaderHelper::projectionTypeToString ( projectionType ); colladaTexture->addExtraTechniqueChildParameter ( PROFILE_MAYA, MAYA_PROJECTION_ELEMENT, MAYA_PROJECTION_TYPE_PARAMETER, strProjectionType ); MMatrix projectionMx; DagHelper::getPlugValue ( projection, ATTR_PLACEMENT_MATRIX, projectionMx ); double sceneMatrix[4][4]; convertMayaMatrixToTransposedDouble4x4 ( sceneMatrix, projectionMx, getTolerance () ); // Convert the maya internal unit type of the transform part of the // matrix from centimeters into the working units of the current scene! for ( uint i=0; i<3; ++i) sceneMatrix [i][3] = MDistance::internalToUI ( sceneMatrix [i][3] ); colladaTexture->addExtraTechniqueChildParameter ( PROFILE_MAYA, MAYA_PROJECTION_ELEMENT, MAYA_PROJECTION_MATRIX_PARAMETER, sceneMatrix ); }
OrientationSphere::OrientationSphere(const ActionOptions&ao): Action(ao), MultiColvarFunction(ao) { // Resize everything that stores a vector now that we know the // number of components unsigned ncomponents=getBaseMultiColvar(0)->getNumberOfQuantities() - 5; catom_orient.resize( ncomponents ); catom_der.resize( ncomponents ); this_orient.resize( ncomponents ); // Weight of this does not have derivatives weightHasDerivatives=false; // Read in the switching function std::string sw, errors; parse("SWITCH",sw); if(sw.length()>0){ switchingFunction.set(sw,errors); } else { double r_0=-1.0, d_0; int nn, mm; parse("NN",nn); parse("MM",mm); parse("R_0",r_0); parse("D_0",d_0); if( r_0<0.0 ) error("you must set a value for R_0"); switchingFunction.set(nn,mm,r_0,d_0); } log.printf(" degree of overlap in orientation between central molecule and those within %s\n",( switchingFunction.description() ).c_str() ); // Set the link cell cutoff setLinkCellCutoff( 2.*switchingFunction.inverse( getTolerance() ) ); // Finish the setup of the object buildSymmetryFunctionLists(); // And check everything has been read in correctly checkRead(); }
//=========================================================================== // // Purpose : Both curve & pt lie within the same epsion ball. It is not a // simple case, and there is intersection. // This is an uwanted situation. We have to make a result that // is as consistent as possible since we cannot subdivide anymore. // // Written by : Sverre Briseid, SINTEF, Sep 2004. //=========================================================================== void Par1FuncIntersector::microCase() //=========================================================================== { // GO_ERROR("Not yet implemented!", InputError()); // Fetch all intersection points belonging to the two curves // The intersection points should be sorted according to the parameter // of one of the curves vector<shared_ptr<IntersectionPoint> > int_pts; int_results_->getSortedIntersections(int_pts); int ki; if (int_pts.size() == 0) { // No intersection point exist. Construct one internal to the two // curves // It is probably good enough to take the midpoint since the // curve is so small double mid_par1 = 0.5*(func_int_->startParam(0) + func_int_->endParam(0)); double C_par = C_->startParam(0); // Well, that would be 0.0. int_results_->addIntersectionPoint(func_int_, C_, getTolerance(), &mid_par1, &C_par); } else if (int_pts.size() == 1) { // One intersection point. Leave it like this. ; } else { // More than one intersection point. Connect. for (ki=1; ki<int(int_pts.size()); ki++) int_pts[ki-1]->connectTo(int_pts[ki], MICRO_PAR1FUNC); } }
// -------------------------------------------- void LightImporter::setSpotLightAttributes ( const COLLADAFW::Light* light, MayaDM::Light* mayaLight ) { MayaDM::SpotLight* spotLight = (MayaDM::SpotLight*)mayaLight; // Attenuation in COLLADA is equal to Decay in Maya. double constant = light->getConstantAttenuation (); double linear = light->getLinearAttenuation (); double quadratic = light->getQuadraticAttenuation (); // TODO If light is animated, the values have to change! if ( quadratic > linear && quadratic > constant ) spotLight->setDecayRate ( 2 ); else if ( linear > constant ) spotLight->setDecayRate ( 1 ); else spotLight->setDecayRate ( 0 ); // Drop-off double dropOff; if ( COLLADABU::Math::Utils::equalsZero ( light->getFallOffExponent (), getTolerance () ) ) dropOff = 0.0; else dropOff = 1.0; // COLLADA 1.4 took out the fallOffScale, for some reason. spotLight->setDropoff ( dropOff ); // Cone and Penumbra Angles double fallOffAngle = light->getFallOffAngle (); spotLight->setConeAngle ( fallOffAngle ); // double penumbraAngle = ( light->getOuterAngle() - light->getFallOffAngle() ) / 2.0f; // spotLight->setPenumbraAngle ( COLLADABU::Math::Utils::degToRad ( penumbraAngle )); }
bool ActionVolume::inVolumeOfInterest( const unsigned& curr ) const { Vector catom_pos=getPntrToMultiColvar()->getCentralAtomPos( curr ); Vector wdf; Tensor vir; std::vector<Vector> refders( getNumberOfAtoms() ); double weight=calculateNumberInside( catom_pos, wdf, vir, refders ); if( not_in ) weight = 1.0 - weight; if( weight<getTolerance() ) return false; return true; }
void SpathVessel::calculate( const unsigned& current, MultiValue& myvals, std::vector<double>& buffer, std::vector<unsigned>& der_index ) const { double pp=mymap->getPropertyValue( current, getLabel() ), weight=myvals.get(0); if( weight<getTolerance() ) return; unsigned nderivatives=getFinalValue()->getNumberOfDerivatives(); buffer[bufstart] += weight*pp; buffer[bufstart+1+nderivatives] += weight; if( getAction()->derivativesAreRequired() ) { myvals.chainRule( 0, 0, 1, 0, pp, bufstart, buffer ); myvals.chainRule( 0, 1, 1, 0, 1.0, bufstart, buffer ); } }
bool Mean::calculate(){ double weight=getAction()->getElementValue(wnum); plumed_dbg_assert( weight>=getTolerance() ); addValueIgnoringTolerance( 1, weight ); double colvar=getAction()->getElementValue(0); addValueIgnoringTolerance( 0, weight*colvar ); getAction()->chainRuleForElementDerivatives( 0, 0, weight, this ); if(diffweight){ getAction()->chainRuleForElementDerivatives( 0, wnum, colvar, this ); getAction()->chainRuleForElementDerivatives( 1, wnum, 1.0, this ); } return true; }
void FunctionVessel::calculate( const unsigned& current, MultiValue& myvals, std::vector<double>& buffer, std::vector<unsigned>& der_list ) const { unsigned nderivatives=getFinalValue()->getNumberOfDerivatives(); double weight=myvals.get(0); plumed_dbg_assert( weight>=getTolerance() ); // This deals with the value double dval, f=calcTransform( myvals.get(mycomp), dval ); if( norm ){ if( usetol && weight<getTolerance() ) return; buffer[bufstart+1+nderivatives] += weight; if( diffweight ) myvals.chainRule( 0, 1, 1, 0, 1.0, bufstart, buffer ); } double contr=weight*f; if( usetol && contr<getTolerance() ) return; buffer[bufstart] += contr; if( diffweight ) myvals.chainRule( 0, 0, 1, 0, f, bufstart, buffer ); if( getAction()->derivativesAreRequired() && fabs(dval)>0.0 ) myvals.chainRule( mycomp, 0, 1, 0, weight*dval, bufstart, buffer ); return; }
double OrientationSphere::compute(){ // Make sure derivatives for central atom are only calculated once VectorMultiColvar* vv = dynamic_cast<VectorMultiColvar*>( getBaseMultiColvar(0) ); vv->firstcall=true; weightHasDerivatives=true; // The weight has no derivatives really double sw, value=0, denom=0, dot, f_dot, dot_df, dfunc; Vector distance; getVectorForBaseTask(0, catom_orient ); for(unsigned i=1;i<getNAtoms();++i){ distance=getSeparation( getPositionOfCentralAtom(0), getPositionOfCentralAtom(i) ); sw = switchingFunction.calculateSqr( distance.modulo2(), dfunc ); if( sw>=getTolerance() ){ getVectorForBaseTask( i, this_orient ); // Calculate the dot product wrt to this position dot=0; for(unsigned k=0;k<catom_orient.size();++k) dot+=catom_orient[k]*this_orient[k]; f_dot = transformDotProduct( dot, dot_df ); // N.B. We are assuming here that the imaginary part of the dot product is zero for(unsigned k=0;k<catom_orient.size();++k){ this_orient[k]*=sw*dot_df; catom_der[k]=sw*dot_df*catom_orient[k]; } // Set the derivatives wrt of the numerator addOrientationDerivatives( 0, this_orient ); addOrientationDerivatives( i, catom_der ); addCentralAtomsDerivatives( 0, 0, f_dot*(-dfunc)*distance ); addCentralAtomsDerivatives( i, 0, f_dot*(dfunc)*distance ); addBoxDerivatives( f_dot*(-dfunc)*Tensor(distance,distance) ); value += sw*f_dot; // Set the derivatives wrt to the numerator addCentralAtomsDerivatives( 0, 1, (-dfunc)*distance ); addCentralAtomsDerivatives( i, 1, (dfunc)*distance ); addBoxDerivativesOfWeight( (-dfunc)*Tensor(distance,distance) ); denom += sw; } } // Now divide everything unsigned nder = getNumberOfDerivatives(); for(unsigned i=0;i<nder;++i){ setElementDerivative( i, getElementDerivative(i)/denom - (value*getElementDerivative(nder+i))/(denom*denom) ); setElementDerivative( nder + i, 0.0 ); } weightHasDerivatives=false; // Weight has no derivatives we just use the holder for weight to store some stuff return value / denom; }
//=========================================================================== // // Purpose : Given two parametric curve in a simple case situation, iterate // to the intersection point, if any. // // Written by : Sverre Briseid, SINTEF, Sep 2004 // //=========================================================================== int Par1FuncIntersector::updateIntersections() //=========================================================================== { // Fetch already existing intersection points vector<shared_ptr<IntersectionPoint> > int_pts; int_results_->getIntersectionPoints(int_pts); if (int_pts.size() > 0) { // At most one intersection point is expected. One or more points // exist already. Leave it like this. // @@sbr Do we expect object to be monotone? return 0; } // Iterate to an intersection point between the two curves double par, dist, tmin, tmax; doIterate(par, dist, tmin, tmax); if ((par != tmin) && (par != tmax) && (dist <= epsge_->getEpsge())) { // An intersection point is found. Represent it in the data // structure // @@@ vsk, In sisl there is a check if the found intersection // point is very close to the endpoints of the curve. In that case // it is dismissed since the intersections at the endpoints are found // already. Here we have already checked if there exist any // intersection points. Thus, we know that there does not exist any // intersection point at the endpoint. // @@sbr But for tangential intersections an endpoint may not be discovered ... // As the int_pts.size() == 0 and an intersection point nevertheless exist // this should be such a (or similar) situation. // @@sbr Another approach could be to avoid subdividing if the obj (2d) // is monotone in that direction. int_results_->addIntersectionPoint(func_int_, C_, getTolerance(), &par, NULL); return 1; // A new point is found } //#endif // 0 return 0; }
void MultiColvarBase::performTask( const unsigned& task_index, const unsigned& current, MultiValue& myvals ) const { AtomValuePack myatoms( myvals, this ); // Retrieve the atom list if( !setupCurrentAtomList( current, myatoms ) ) return; // Do a quick check on the size of this contribution calculateWeight( myatoms ); if( myatoms.getValue(0)<getTolerance() ){ updateActiveAtoms( myatoms ); return; } // Compute everything double vv=doCalculation( task_index, myatoms ); myatoms.setValue( 1, vv ); return; }
typename ContactDistanceCalc<BasicTraits,BVOL,Metric>::ResultT ContactDistanceCalc<BasicTraits,BVOL,Metric>::PrimPrimCollision (AdapterType* p0, AdapterType* p1) { // Transform from model space 1 to model space 0 PointClass tp1[3]; m_M1ToM0.mult(p1->getPosition(0), tp1[0]); m_M1ToM0.mult(p1->getPosition(1), tp1[1]); m_M1ToM0.mult(p1->getPosition(2), tp1[2]); // perform triangle-triangle distance calculation ++m_numPrimPrimTests; PointClass min0, min1; Real dist = genvis::triTriDistance(min0, min1, p0->getPosition(), tp1); if (dist <= getTolerance()) { // update minimum distance if (dist < getDistance()) { setDistance(dist); // keep track of contact pairs m_contacts.insert(m_contacts.begin(), CollisionPair(p0, p1)); //m_contacts[0].setData(new Distance()); CollisionInterface<OpenSGTriangleBase<BasicTraits>,Distance> result(m_contacts[0]); result.getData().distance = dist; m_M0.mult(min0, result.getData().p1); m_M0.mult(min1, result.getData().p2); #ifdef GV_WITH_LINEGEOMETRY if (getLineGeometry() != NullFC) { beginEditCP(getLineGeometry()); getLineGeometry()->setValue(result.getData().p1, 1); getLineGeometry()->setValue(result.getData().p2, 0); endEditCP(getLineGeometry()); } #endif } else { // keep track of contact pairs m_contacts.push_back(CollisionPair(p0, p1)); //m_contacts[m_contacts.size()-1].setData(new Distance()); CollisionInterface<OpenSGTriangleBase<BasicTraits>,Distance> result(m_contacts[m_contacts.size()-1]); result.getData().distance = dist; } } return DoubleTraverserBase<BasicTraits>::CONTINUE; }
void MultiColvarBase::performTask(){ // Currently no atoms have derivatives so deactivate those that are active atoms_with_derivatives.deactivateAll(); // Currently no central atoms have derivatives so deactive them all atomsWithCatomDer.deactivateAll(); // Retrieve the atom list if( !setupCurrentAtomList( getCurrentTask() ) ) return; // Do a quick check on the size of this contribution calculateWeight(); // printf("HELLO WEIGHT %f \n",getElementValue(1) ); if( getElementValue(1)<getTolerance() ){ updateActiveAtoms(); return; } // Compute everything double vv=doCalculation(); // Set the value of this element in ActionWithVessel setElementValue( 0, vv ); return; }
//============================================================================== bool IpoptSolver::solve() { // Change some options // Note: The following choices are only examples, they might not be // suitable for your optimization problem. mIpoptApp->Options()->SetNumericValue("tol", getTolerance()); mIpoptApp->Options()->SetStringValue("output_file", getResultFileName()); std::size_t freq = mProperties.mIterationsPerPrint; if(freq > 0) { mIpoptApp->Options()->SetNumericValue("print_frequency_iter", freq); } else { mIpoptApp->Options()->SetNumericValue( "print_frequency_iter", std::numeric_limits<int>::infinity()); } // Intialize the IpoptApplication and process the options Ipopt::ApplicationReturnStatus init_status = mIpoptApp->Initialize(); if (init_status != Ipopt::Solve_Succeeded) { dterr << "[IpoptSolver::solve] Error during ipopt initialization.\n"; assert(false); return false; } // Ask Ipopt to solve the problem Ipopt::ApplicationReturnStatus status = mIpoptApp->OptimizeTNLP(mNlp); if (status == Ipopt::Solve_Succeeded) return true; else return false; }
//--------------------------------------- void MaterialExporter::setSetParam ( const cgfxShaderNode* shaderNodeCgfx, const cgfxAttrDef* attribute ) { COLLADASW::StreamWriter* streamWriter = mDocumentExporter->getStreamWriter(); String attributeName = attribute->fName.asChar(); cgfxAttrDef::cgfxAttrType attributeType = attribute->fType; switch ( attributeType ) { case cgfxAttrDef::kAttrTypeBool: { COLLADASW::SetParamBool setParam ( streamWriter ); setParam.openParam ( attributeName ); setParam.appendValues ( attribute->fNumericDef && attribute->fNumericDef[0] ); setParam.closeParam (); break; } case cgfxAttrDef::kAttrTypeInt: { COLLADASW::SetParamInt setParam ( streamWriter ); setParam.openParam ( attributeName ); setParam.appendValues ( (int) attribute->fNumericDef[0] ); setParam.closeParam(); break; } case cgfxAttrDef::kAttrTypeString: { COLLADASW::SetParamString setParam ( streamWriter ); setParam.openParam ( attributeName ); if ( attribute->fStringDef != NULL ) setParam.appendValues ( String ( attribute->fStringDef.asChar() ) ); setParam.closeParam(); break; } case cgfxAttrDef::kAttrTypeFloat: { COLLADASW::SetParamFloat setParam ( streamWriter ); setParam.openParam ( attributeName ); if ( attribute->fNumericDef!=NULL /*&& attribute->fNumericDef[0]!=0*/ ) setParam.appendValues ( attribute->fNumericDef[0] ); setParam.closeParam(); break; } case cgfxAttrDef::kAttrTypeVector2: { COLLADASW::SetParamFloat2 setParam ( streamWriter ); setParam.openParam ( attributeName ); for ( int i=0; i<attribute->fSize; ++i ) { if ( attribute->fNumericDef!=NULL /*&& attribute->fNumericDef[i]!=0*/ ) { double val = attribute->fNumericDef[i]; setParam.appendValues( val ); } } setParam.closeParam(); break; } case cgfxAttrDef::kAttrTypeVector3: case cgfxAttrDef::kAttrTypeColor3: { COLLADASW::SetParamFloat3 setParam ( streamWriter ); setParam.openParam ( attributeName ); for ( int i=0; i<attribute->fSize; ++i ) { if ( attribute->fNumericDef!=NULL /*&& attribute->fNumericDef[i]!=0*/ ) { double val = attribute->fNumericDef[i]; setParam.appendValues( val ); } } setParam.closeParam(); break; } case cgfxAttrDef::kAttrTypeVector4: case cgfxAttrDef::kAttrTypeColor4: { COLLADASW::SetParamFloat4 setParam ( streamWriter ); setParam.openParam ( attributeName ); for ( int i=0; i<attribute->fSize; ++i ) { if ( attribute->fNumericDef!=NULL /*&& attribute->fNumericDef[i]!=0*/ ) { double val = attribute->fNumericDef[i]; setParam.appendValues( val ); } } setParam.closeParam(); break; } case cgfxAttrDef::kAttrTypeWorldDir: case cgfxAttrDef::kAttrTypeWorldPos: { // Read the value double tmp[4]; for ( int i=0; i<attribute->fSize; ++i ) { tmp[i] = attribute->fNumericDef[i]; } if (attribute->fSize == 3) tmp[3] = 1.0; // Find the coordinate space, and whether it is a point or a vector int base = cgfxAttrDef::kAttrTypeFirstPos; if (attribute->fType <= cgfxAttrDef::kAttrTypeLastDir) base = cgfxAttrDef::kAttrTypeFirstDir; int space = attribute->fType - base; // Compute the transform matrix MMatrix mat; switch (space) { /* case 0: object space, handled in view dependent method */ case 1: /* world space - do nothing, identity */ break; /* case 2: eye space, unsupported yet */ /* case 3: clip space, unsupported yet */ /* case 4: screen space, unsupported yet */ } if ( base == cgfxAttrDef::kAttrTypeFirstPos ) { MPoint point(tmp[0], tmp[1], tmp[2], tmp[3]); point *= mat; tmp[0] = point.x; tmp[1] = point.y; tmp[2] = point.z; tmp[3] = point.w; } else { MVector vec(tmp[0], tmp[1], tmp[2]); vec *= mat; tmp[0] = vec.x; tmp[1] = vec.y; tmp[2] = vec.z; tmp[3] = 1; } COLLADASW::SetParamFloat4 setParam ( streamWriter ); setParam.openParam ( attributeName ); setParam.appendValues( tmp[0], tmp[1], tmp[2], tmp[3] ); setParam.closeParam(); break; } case cgfxAttrDef::kAttrTypeMatrix: case cgfxAttrDef::kAttrTypeWorldMatrix: case cgfxAttrDef::kAttrTypeViewMatrix: case cgfxAttrDef::kAttrTypeProjectionMatrix: case cgfxAttrDef::kAttrTypeWorldViewMatrix: case cgfxAttrDef::kAttrTypeWorldViewProjectionMatrix: { COLLADASW::SetParamFloat4x4 setParam ( streamWriter ); setParam.openParam ( attributeName ); MMatrix mayaMatrix; double* p = &mayaMatrix.matrix[0][0]; for ( int k=0; k<attribute->fSize; ++k ) { p[k] = attribute->fNumericDef[k]; } MMatrix wMatrix, vMatrix, pMatrix, sMatrix; MMatrix wvMatrix, wvpMatrix, wvpsMatrix; { float tmp[4][4]; wMatrix.setToIdentity(); glGetFloatv(GL_MODELVIEW_MATRIX, &tmp[0][0]); wvMatrix = MMatrix(tmp); vMatrix = wMatrix.inverse() * wvMatrix; glGetFloatv(GL_PROJECTION_MATRIX, &tmp[0][0]); pMatrix = MMatrix(tmp); wvpMatrix = wvMatrix * pMatrix; float vpt[4]; float depth[2]; glGetFloatv(GL_VIEWPORT, vpt); glGetFloatv(GL_DEPTH_RANGE, depth); // Construct the NDC -> screen space matrix // float x0, y0, z0, w, h, d; x0 = vpt[0]; y0 = vpt[1]; z0 = depth[0]; w = vpt[2]; h = vpt[3]; d = depth[1] - z0; // Make a reference to ease the typing // double* s = &sMatrix.matrix[0][0]; s[ 0] = w/2; s[ 1] = 0.0; s[ 2] = 0.0; s[ 3] = 0.0; s[ 4] = 0.0; s[ 5] = h/2; s[ 6] = 0.0; s[ 7] = 0.0; s[ 8] = 0.0; s[ 9] = 0.0; s[10] = d/2; s[11] = 0.0; s[12] = x0+w/2; s[13] = y0+h/2; s[14] = z0+d/2; s[15] = 1.0; wvpsMatrix = wvpMatrix * sMatrix; } switch ( attribute->fType ) { case cgfxAttrDef::kAttrTypeWorldMatrix: mayaMatrix = wMatrix; break; case cgfxAttrDef::kAttrTypeViewMatrix: mayaMatrix = vMatrix; break; case cgfxAttrDef::kAttrTypeProjectionMatrix: mayaMatrix = pMatrix; break; case cgfxAttrDef::kAttrTypeWorldViewMatrix: mayaMatrix = wvMatrix; break; case cgfxAttrDef::kAttrTypeWorldViewProjectionMatrix: mayaMatrix = wvpMatrix; break; default: break; } if (attribute->fInvertMatrix) mayaMatrix = mayaMatrix.inverse(); if (!attribute->fTransposeMatrix) mayaMatrix = mayaMatrix.transpose(); double matrix[4][4]; convertMayaMatrixToTransposedDouble4x4 ( matrix, mayaMatrix, getTolerance () ); setParam.appendValues( matrix ); setParam.closeParam(); break; } case cgfxAttrDef::kAttrTypeColor1DTexture: case cgfxAttrDef::kAttrTypeColor2DTexture: case cgfxAttrDef::kAttrTypeColor3DTexture: case cgfxAttrDef::kAttrTypeColor2DRectTexture: case cgfxAttrDef::kAttrTypeNormalTexture: case cgfxAttrDef::kAttrTypeBumpTexture: case cgfxAttrDef::kAttrTypeCubeTexture: case cgfxAttrDef::kAttrTypeEnvTexture: case cgfxAttrDef::kAttrTypeNormalizationTexture: { CGparameter cgParameter = attribute->fParameterHandle; HwShaderExporter hwShaderExporter ( mDocumentExporter ); hwShaderExporter.setShaderFxFileUri ( getShaderFxFileUri () ); MObject shaderNode = shaderNodeCgfx->thisMObject(); hwShaderExporter.exportSampler ( shaderNode, cgParameter, false ); // ------------------------------- // String imageName = attribute->fStringDef.asChar(); // // MObject oNode = shaderNodeCgfx->thisMObject(); // MFnDependencyNode oNodeFn ( oNode ); // String oNodeName = oNodeFn.name().asChar(); // cgfxShader1 // // MPlug plug; // if ( DagHelper::getPlugConnectedTo( oNode, attributeName, plug ) ) // { // String plugName = plug.name().asChar(); // file1.outColor // MObject textureNode = plug.node(); // // //COLLADASW::Surface::SurfaceType surfaceType; // COLLADASW::Sampler::SamplerType samplerType; // COLLADASW::ValueType::ColladaType samplerValueType; // // switch ( attributeType ) // { // case cgfxAttrDef::kAttrTypeColor1DTexture: // //surfaceType = COLLADASW::Surface::SURFACE_TYPE_1D; // samplerType = COLLADASW::Sampler::SAMPLER_TYPE_1D; // samplerValueType = COLLADASW::ValueType::SAMPLER_1D; // break; // case cgfxAttrDef::kAttrTypeColor2DTexture: // case cgfxAttrDef::kAttrTypeNormalTexture: // case cgfxAttrDef::kAttrTypeBumpTexture: // //surfaceType = COLLADASW::Surface::SURFACE_TYPE_2D; // samplerType = COLLADASW::Sampler::SAMPLER_TYPE_2D; // samplerValueType = COLLADASW::ValueType::SAMPLER_2D; // break; // case cgfxAttrDef::kAttrTypeColor3DTexture: // //surfaceType = COLLADASW::Surface::SURFACE_TYPE_3D; // samplerType = COLLADASW::Sampler::SAMPLER_TYPE_3D; // samplerValueType = COLLADASW::ValueType::SAMPLER_3D; // break; // case cgfxAttrDef::kAttrTypeColor2DRectTexture: // //surfaceType = COLLADASW::Surface::SURFACE_TYPE_RECT; // samplerType = COLLADASW::Sampler::SAMPLER_TYPE_RECT; // samplerValueType = COLLADASW::ValueType::SAMPLER_RECT; // break; // case cgfxAttrDef::kAttrTypeCubeTexture: // case cgfxAttrDef::kAttrTypeEnvTexture: // case cgfxAttrDef::kAttrTypeNormalizationTexture: // //surfaceType = COLLADASW::Surface::SURFACE_TYPE_CUBE; // samplerType = COLLADASW::Sampler::SAMPLER_TYPE_CUBE; // samplerValueType = COLLADASW::ValueType::SAMPLER_CUBE; // break; // default: // //surfaceType = COLLADASW::Surface::SURFACE_TYPE_UNTYPED; // samplerType = COLLADASW::Sampler::SAMPLER_TYPE_UNSPECIFIED; // samplerValueType = COLLADASW::ValueType::VALUE_TYPE_UNSPECIFIED; // } // // // Write the params elements // setSetParamTexture ( attribute, textureNode, samplerType, samplerValueType ); // } } } }
void Steinhardt::calculateVector(){ double dfunc, dpoly_ass, md, tq6, itq6, real_z, imag_z; Vector distance, dz, myrealvec, myimagvec, real_dz, imag_dz; // The square root of -1 std::complex<double> ii( 0.0, 1.0 ), dp_x, dp_y, dp_z; double sw, poly_ass, dlen, nbond=0.0; std::complex<double> powered; for(unsigned i=1;i<getNAtoms();++i){ distance=getSeparation( getPosition(0), getPosition(i) ); dlen=distance.modulo(); sw = switchingFunction.calculate( dlen, dfunc ); if( sw>=getTolerance() ){ nbond += sw; // Accumulate total number of bonds double dlen3 = dlen*dlen*dlen; // Store derivatives of weight MultiColvarBase::addAtomsDerivatives( 0, getAtomIndex(0), (-dfunc)*distance ); MultiColvarBase::addAtomsDerivatives( 0, getAtomIndex(i), (+dfunc)*distance ); MultiColvarBase::addBoxDerivatives( 0, (-dfunc)*Tensor( distance,distance ) ); // Do stuff for m=0 poly_ass=deriv_poly( 0, distance[2]/dlen, dpoly_ass ); // Derivatives of z/r wrt x, y, z dz = -( distance[2] / dlen3 )*distance; dz[2] += (1.0 / dlen); // Derivative wrt to the vector connecting the two atoms myrealvec = (+sw)*dpoly_ass*dz + poly_ass*(+dfunc)*distance; // Accumulate the derivatives addAtomsDerivative( tmom, 0, -myrealvec ); addAtomsDerivative( tmom, i, myrealvec ); addBoxDerivatives( tmom, Tensor( -myrealvec,distance ) ); // And store the vector function addComponent( tmom, sw*poly_ass ); // The complex number of which we have to take powers std::complex<double> com1( distance[0]/dlen ,distance[1]/dlen ); // Do stuff for all other m values for(unsigned m=1;m<=tmom;++m){ // Calculate Legendre Polynomial poly_ass=deriv_poly( m, distance[2]/dlen, dpoly_ass ); // Calculate powe of complex number powered=pow(com1,m-1); md=static_cast<double>(m); // Real and imaginary parts of z real_z = real(com1*powered); imag_z = imag(com1*powered ); // Calculate steinhardt parameter tq6=poly_ass*real_z; // Real part of steinhardt parameter itq6=poly_ass*imag_z; // Imaginary part of steinhardt parameter // Derivatives wrt ( x/r + iy )^m dp_x = md*powered*( (1.0/dlen)-(distance[0]*distance[0])/dlen3-ii*(distance[0]*distance[1])/dlen3 ); dp_y = md*powered*( ii*(1.0/dlen)-(distance[0]*distance[1])/dlen3-ii*(distance[1]*distance[1])/dlen3 ); dp_z = md*powered*( -(distance[0]*distance[2])/dlen3-ii*(distance[1]*distance[2])/dlen3 ); // Derivatives of real and imaginary parts of above real_dz[0] = real( dp_x ); real_dz[1] = real( dp_y ); real_dz[2] = real( dp_z ); imag_dz[0] = imag( dp_x ); imag_dz[1] = imag( dp_y ); imag_dz[2] = imag( dp_z ); // Complete derivative of steinhardt parameter myrealvec = (+sw)*dpoly_ass*real_z*dz + (+dfunc)*distance*tq6 + (+sw)*poly_ass*real_dz; myimagvec = (+sw)*dpoly_ass*imag_z*dz + (+dfunc)*distance*itq6 + (+sw)*poly_ass*imag_dz; // Real part addComponent( tmom+m, sw*tq6 ); addAtomsDerivative( tmom+m, 0, -myrealvec ); addAtomsDerivative( tmom+m, i, myrealvec ); addBoxDerivatives( tmom+m, Tensor( -myrealvec,distance ) ); // Imaginary part addImaginaryComponent( tmom+m, sw*itq6 ); addImaginaryAtomsDerivative( tmom+m, 0, -myimagvec ); addImaginaryAtomsDerivative( tmom+m, i, myimagvec ); addImaginaryBoxDerivatives( tmom+m, Tensor( -myimagvec,distance ) ); // Store -m part of vector double pref=pow(-1.0,m); // -m part of vector is just +m part multiplied by (-1.0)**m and multiplied by complex // conjugate of Legendre polynomial // Real part addComponent( tmom-m, pref*sw*tq6 ); addAtomsDerivative( tmom-m, 0, -pref*myrealvec ); addAtomsDerivative( tmom-m, i, pref*myrealvec ); addBoxDerivatives( tmom-m, pref*Tensor( -myrealvec,distance ) ); // Imaginary part addImaginaryComponent( tmom-m, -pref*sw*itq6 ); addImaginaryAtomsDerivative( tmom-m, 0, pref*myimagvec ); addImaginaryAtomsDerivative( tmom-m, i, -pref*myimagvec ); addImaginaryBoxDerivatives( tmom-m, pref*Tensor( myimagvec,distance ) ); } } else { removeAtomRequest( i, sw ); } } // Normalize setElementValue(0, nbond ); updateActiveAtoms(); for(unsigned i=0;i<2*getNumberOfComponentsInVector();++i) quotientRule( 5+i, 0, 5+i ); // Clear tempory stuff clearDerivativesAfterTask(0); }