void FB_CTUD_DINT::executeEvent(int pa_nEIID) { if (pa_nEIID == scm_nEventREQID) { if (true == R()) { CV() = 0; } else { if (true == LD()) { CV() = PV(); } else { if (!(CU() && CD())) { if ((CU() && (CV() < CIEC_DINT::scm_nMaxVal))) { CV() = CV() + 1; } else { if ((CD() && (CV() > CIEC_DINT::scm_nMinVal))) { CV() = CV() - 1; } } } } } QU() = (CV() >= PV()); QD() = (CV() <= 0); sendOutputEvent(scm_nEventCNFID); } }
void FB_CTUD::executeEvent(AppBlocInfo pa_stAppBlocInfo, EVENT_UID pa_unEIID) { if (m_unEventREQID == pa_unEIID) { if (true == R()) { CV() = 0; } else { if (true == LD()) { CV() = PV(); } else { if (!(CU() && CD())) { if ((CU() && (CV() < CIEC_DT_INT::scm_nMaxVal))) { CV() = static_cast<FzrteInt16>(CV() + 1); } else { if ((CD() && (CV() > CIEC_DT_INT::scm_nMinVal))) { CV() = static_cast<FzrteInt16>(CV() - 1); } } } } } QU() = (CV() >= PV()); QD() = (CV() <= 0); SendOutput(m_unEventCNFID); } }
Rectangulo::Rectangulo(int ancho, int alto, int size, PV * esqSupIzq) : Obstaculo() { PV NO, NE, SO, SE; NO = PV(esqSupIzq->getX(), esqSupIzq->getY()); NE = PV(esqSupIzq->getX()+ancho, esqSupIzq->getY()); SE = PV(esqSupIzq->getX()+ancho, esqSupIzq->getY()-alto); SO = PV(esqSupIzq->getX(), esqSupIzq->getY()-alto); vertices = new PV*[4]; vertices[0] = new PV(esqSupIzq->getX(), esqSupIzq->getY()); vertices[1] = new PV(esqSupIzq->getX()+ancho, esqSupIzq->getY()); vertices[2] = new PV(esqSupIzq->getX()+ancho, esqSupIzq->getY()-alto); vertices[3] = new PV(esqSupIzq->getX(), esqSupIzq->getY()-alto); posicion = esqSupIzq; nVertices = size; calculaNormales(); }
void NaGeVector3D::Rotate(const NaGeOneAxis& Ax, double ang) { NaGeOneAxis ax = Ax; NaGeVector3D P1 = ax.GetOrigin(); NaGeVector3D V = ax.GetDirection(); V.Normalize(); NaGeMatrix33 M; NaGeVector3D PV(*this); M.SetRotation(V, ang); NaGeVector3D RV = M*(PV-P1); RV = RV + P1; *this = RV; }
void FB_CTD_UDINT::executeEvent(int pa_nEIID){ if(pa_nEIID == scm_nEventREQID){ if(true == LD()){ CV() = PV(); } else if( (true == CD()) && (CV() > CIEC_UDINT::scm_nMinVal)){ CV() = CV() - 1; } Q() = (CV() <= 0); sendOutputEvent(scm_nEventCNFID); } }
void NaGePoint2D::Mirror(const NaGeOneAxis2D& Ax) { NaGePoint2D P1 = Ax.GetPosition(); NaGePoint2D P = (*this); NaGeVector2D N = Ax.GetDirection(); NaGeLine2D L(P1, N); double D = L.Distance(P); NaGeVector2D Q = L.NormalThrough(P) * D * (-2.0); NaGeVector2D PV((*this)); NaGeVector2D R = PV + Q; this->SetParam(R.GetX(), R.GetY()); }
void FB_CTU::executeEvent(int pa_nEIID){ if(pa_nEIID == scm_nEventREQID){ if(true == R()){ CV() = 0; } else if( (true == CU()) && (CV() < CIEC_INT::scm_nMaxVal)){ CV() = static_cast<TForteInt16>(CV() + 1); } Q() = (CV() >= PV()); sendOutputEvent(scm_nEventCNFID); } }
void FB_CTU::executeEvent(AppBlocInfo pa_stAppBlocInfo, EVENT_UID pa_unEIID) { if (m_unEventREQID == pa_unEIID) { if (true == R()) { CV() = 0; } else if ((true == CU()) && (CV() < CIEC_DT_INT::scm_nMaxVal)) { CV() = static_cast<FzrteInt16>(CV() + 1); } Q() = (CV() >= PV()); SendOutput(m_unEventCNFID); } }
void FB_CTD::executeEvent(AppBlocInfo pa_stAppBlocInfo, EVENT_UID pa_unEIID) { if (m_unEventREQID == pa_unEIID) { if (true == LD()) { CV() = PV(); } else if ((true == CD()) && (CV() > CIEC_DT_INT::scm_nMinVal)) { CV() = static_cast<FzrteInt16>(CV() - 1); } Q() = (CV() <= 0); SendOutput(m_unEventCNFID); } }
void ImageMean<T>::setup_pv(const ImageSequence& images) { // the image sequence must be consistent, or we cannot do // anything about it if (!consistent(images)) { throw std::runtime_error("images not consistent"); } // we need access to the pixels, but we want to avoid all the // time consuming dynamic casts, so we create a vector of // PixelValue objects, which already do the dynamic casts // in the constructor ImageSequence::const_iterator i; for (i = images.begin(); i != images.end(); i++) { pvs.push_back(PV(*i)); } }
void ParametricSurface<Real>::GetFrame (Real u, Real v, Vector3<Real>& position, Vector3<Real>& tangent0, Vector3<Real>& tangent1, Vector3<Real>& normal) const { position = P(u, v); tangent0 = PU(u, v); tangent1 = PV(u, v); tangent0.Normalize(); // T0 tangent1.Normalize(); // temporary T1 just to compute N normal = tangent0.UnitCross(tangent1); // N // The normalized first derivatives are not necessarily orthogonal. // Recompute T1 so that {T0,T1,N} is an orthonormal set. tangent1 = normal.Cross(tangent0); }
void AddPartialSharedRanges(Overlap & ovrlp, // out Partition const& Prtng, int p, Part2Cell const& P2C, VertexRange const& shared_v, FacetRange const& shared_f, VtxCorr const& vtx_corr, FacetCorr const& facet_corr) { // for(int p = 0; p < (int) Prtng.NumOfPartitions(); ++p) { typedef typename FacetRange::ElementIterator RgeFacetIterator; for(RgeFacetIterator f = shared_f.FirstElement(); ! f.IsDone(); ++f) { int q = Prtng.other_partition(*f,p); // if(p > q) { // <---- unsymmetric if( (P2C(q) < P2C(p)) || (P2C(p) == P2C(q) && p > q)) { // <---- unsymmetric ovrlp[P2C(p)].facets(P2C(q)).shared().push_back(*f); // local if( q < 0) ovrlp[P2C(q)].facets(P2C(p)).shared().push_back(facet_corr(*f)); // "remote" else ovrlp[P2C(q)].facets(P2C(p)).shared().push_back(*f); // "local" } } // } PartitionsByVertex<Partition> PV(Prtng); typedef typename PartitionsByVertex<Partition>::PartitionOfVertexIterator VtxPartIterator; // for(int p = 0; p < (int) Prtng.NumOfPartitions(); ++p) { // CoarseCell P(Prtng.PartCell()); typedef typename VertexRange::ElementIterator RgeVertexIterator; for(RgeVertexIterator v = shared_v.FirstElement(); ! v.IsDone(); ++v) { for(VtxPartIterator qi = PV.begin(*v); qi != PV.end(*v); ++qi) { int q = *qi; // if(p > q) { // <---- unsymmetric if( (P2C(q) < P2C(p)) || (P2C(p) == P2C(q) && p > q)) { // <---- unsymmetric ovrlp[P2C(p)].vertices(P2C(q)).shared().push_back(*v); // local if( q < 0) ovrlp[P2C(q)].vertices(P2C(p)).shared().push_back(vtx_corr(*v)); // "remote" else ovrlp[P2C(q)].vertices(P2C(p)).shared().push_back(*v); // "local" } } } // } }
void ParametricSurface<Real>::ComputePrincipalCurvatureInfo (Real u, Real v, Real& curv0, Real& curv1, Vector3<Real>& dir0, Vector3<Real>& dir1) { // Tangents: T0 = (x_u,y_u,z_u), T1 = (x_v,y_v,z_v) // Normal: N = Cross(T0,T1)/Length(Cross(T0,T1)) // Metric Tensor: G = +- -+ // | Dot(T0,T0) Dot(T0,T1) | // | Dot(T1,T0) Dot(T1,T1) | // +- -+ // // Curvature Tensor: B = +- -+ // | -Dot(N,T0_u) -Dot(N,T0_v) | // | -Dot(N,T1_u) -Dot(N,T1_v) | // +- -+ // // Principal curvatures k are the generalized eigenvalues of // // Bw = kGw // // If k is a curvature and w=(a,b) is the corresponding solution to // Bw = kGw, then the principal direction as a 3D vector is d = a*U+b*V. // // Let k1 and k2 be the principal curvatures. The mean curvature // is (k1+k2)/2 and the Gaussian curvature is k1*k2. // Compute derivatives. Vector3<Real> derU = PU(u,v); Vector3<Real> derV = PV(u,v); Vector3<Real> derUU = PUU(u,v); Vector3<Real> derUV = PUV(u,v); Vector3<Real> derVV = PVV(u,v); // Compute the metric tensor. Matrix2<Real> metricTensor; metricTensor[0][0] = derU.Dot(derU); metricTensor[0][1] = derU.Dot(derV); metricTensor[1][0] = metricTensor[0][1]; metricTensor[1][1] = derV.Dot(derV); // Compute the curvature tensor. Vector3<Real> normal = derU.UnitCross(derV); Matrix2<Real> curvatureTensor; curvatureTensor[0][0] = -normal.Dot(derUU); curvatureTensor[0][1] = -normal.Dot(derUV); curvatureTensor[1][0] = curvatureTensor[0][1]; curvatureTensor[1][1] = -normal.Dot(derVV); // Characteristic polynomial is 0 = det(B-kG) = c2*k^2+c1*k+c0. Real c0 = curvatureTensor.Determinant(); Real c1 = ((Real)2)*curvatureTensor[0][1]* metricTensor[0][1] - curvatureTensor[0][0]*metricTensor[1][1] - curvatureTensor[1][1]*metricTensor[0][0]; Real c2 = metricTensor.Determinant(); // Principal curvatures are roots of characteristic polynomial. Real temp = Math<Real>::Sqrt(Math<Real>::FAbs(c1*c1 - ((Real)4)*c0*c2)); Real mult = ((Real)0.5)/c2; curv0 = -mult*(c1+temp); curv1 = mult*(-c1+temp); // Principal directions are solutions to (B-kG)w = 0, // w1 = (b12-k1*g12,-(b11-k1*g11)) OR (b22-k1*g22,-(b12-k1*g12)). Real a0 = curvatureTensor[0][1] - curv0*metricTensor[0][1]; Real a1 = curv0*metricTensor[0][0] - curvatureTensor[0][0]; Real length = Math<Real>::Sqrt(a0*a0 + a1*a1); if (length >= Math<Real>::ZERO_TOLERANCE) { dir0 = a0*derU + a1*derV; } else { a0 = curvatureTensor[1][1] - curv0*metricTensor[1][1]; a1 = curv0*metricTensor[0][1] - curvatureTensor[0][1]; length = Math<Real>::Sqrt(a0*a0 + a1*a1); if (length >= Math<Real>::ZERO_TOLERANCE) { dir0 = a0*derU + a1*derV; } else { // Umbilic (surface is locally sphere, any direction principal). dir0 = derU; } } dir0.Normalize(); // Second tangent is cross product of first tangent and normal. dir1 = dir0.Cross(normal); }
void IterativeDeepener::Search(const IDSParams& ids_params, Move* best_move, int* best_move_score, SearchStats* id_search_stats) { std::ostream& out = ids_params.thinking_output ? std::cout : nullstream; ClearState(); StopWatch stop_watch; stop_watch.Start(); movegen_->GenerateMoves(&root_move_array_); out << "# Number of moves at root: " << root_move_array_.size() << std::endl; // No moves to make. Just return by setting invalid move. This can happen if // Search() is called after game ends. if (root_move_array_.size() == 0) { *best_move = Move(); *best_move_score = INF; return; } // Caller provided move ordering and pruning takes priority over move orderer. if (ids_params.pruned_ordered_moves.size()) { root_move_array_ = ids_params.pruned_ordered_moves; } else if (extensions_->move_orderer) { extensions_->move_orderer->Order(&root_move_array_); } assert(root_move_array_.size() > 0); out << "# Number of root moves being searched: " << root_move_array_.size() << std::endl; // If there is only one move to be made, make it without hesitation as search // won't yield anything new. if (root_move_array_.size() == 1) { *best_move = root_move_array_.get(0); *best_move_score = INF; return; } // Iterative deepening starts here. for (unsigned depth = 1; depth <= ids_params.search_depth; ++depth) { // Do not use transposition table moves at the root if ordered/pruned // movelist is passed by the caller as we expect input ordering to be of // highest quality. Also, this avoids transposition table moves that are // not in the list to be brought to the front. if (ids_params.pruned_ordered_moves.size() == 0) { TranspositionTableEntry* tentry = transpos_->Get(board_->ZobristKey()); if (tentry && tentry->best_move.is_valid()) { root_move_array_.PushToFront(tentry->best_move); } } else if (!iteration_stats_.empty()) { root_move_array_.PushToFront(iteration_stats_.back().best_move); } // This will return immediately when timer expires but updates the // iteration_stats_ nevertheless. Results from the last iteration are // acceptable only if search of at least the first root move subtree was // completed. Due to the move-ordering done above, the first root move that // is searched is guaranteed to be the best known move before beginning of // this iteration. So, if a different best move is found before timer // expiry, it is at least better than the previously known best move // (though it might not be the overall best move at this depth because all // the root moves might not be covered). FindBestMove(depth); double elapsed_time = stop_watch.ElapsedTime(); const IterationStat& last_istat = iteration_stats_.back(); // If FindMove could not complete at least the first root move subtree // completely, don't report stats or update best_move as the results are // likely to be incorrect. if (timer_->Lapsed() && last_istat.root_moves_covered == 0) { break; } // Update best_move and stats. *best_move = last_istat.best_move; *best_move_score = last_istat.score; id_search_stats->nodes_searched += last_istat.search_stats.nodes_searched; id_search_stats->nodes_researched += last_istat.search_stats.nodes_researched; id_search_stats->nodes_evaluated += last_istat.search_stats.nodes_evaluated; id_search_stats->search_depth = last_istat.depth; // XBoard style thinking output. if (ids_params.thinking_output) { char output[256]; snprintf(output, 256, "%2d\t%5d\t%5d\t%10d\t%s", depth, last_istat.score, int(elapsed_time), id_search_stats->nodes_evaluated, PV(*best_move).c_str()); std::cout << output << std::endl; } // Don't go any deeper if a win is confirmed or timer has lapsed. if (last_istat.score == WIN || timer_->Lapsed()) { break; } } stop_watch.Stop(); out << "# Time taken for ID search: " << stop_watch.ElapsedTime() << " centis" << std::endl; }
void V(int index) { if (PV(index, 1) < 0) perror ("libthrd.V"); }
void P(int index) { if (PV(index, -1) < 0) perror ("libthrd.P"); }
//converts a FBX mesh to a CC mesh static ccMesh* FromFbxMesh(FbxMesh* fbxMesh, bool alwaysDisplayLoadDialog/*=true*/, bool* coordinatesShiftEnabled/*=0*/, CCVector3d* coordinatesShift/*=0*/) { if (!fbxMesh) return 0; int polyCount = fbxMesh->GetPolygonCount(); //fbxMesh->GetLayer( unsigned triCount = 0; unsigned polyVertCount = 0; //different from vertCount (vertices can be counted multiple times here!) //as we can't load all polygons (yet ;) we already look if we can load any! { unsigned skipped = 0; for (int i=0; i<polyCount; ++i) { int pSize = fbxMesh->GetPolygonSize(i); if (pSize == 3) { ++triCount; polyVertCount += 3; } else if (pSize == 4) { triCount += 2; polyVertCount += 4; } else { ++skipped; } } if (triCount == 0) { ccLog::Warning(QString("[FBX] No triangle or quad found in mesh '%1'! (polygons with more than 4 vertices are not supported for the moment)").arg(fbxMesh->GetName())); return 0; } else if (skipped != 0) { ccLog::Warning(QString("[FBX] Some polygons in mesh '%1' were ignored (%2): polygons with more than 4 vertices are not supported for the moment)").arg(fbxMesh->GetName()).arg(skipped)); return 0; } } int vertCount = fbxMesh->GetControlPointsCount(); if (vertCount <= 0) { ccLog::Warning(QString("[FBX] Mesh '%1' has no vetex or no polygon?!").arg(fbxMesh->GetName())); return 0; } ccPointCloud* vertices = new ccPointCloud("vertices"); ccMesh* mesh = new ccMesh(vertices); mesh->setName(fbxMesh->GetName()); mesh->addChild(vertices); vertices->setEnabled(false); if (!mesh->reserve(static_cast<unsigned>(triCount)) || !vertices->reserve(vertCount)) { ccLog::Warning(QString("[FBX] Not enough memory to load mesh '%1'!").arg(fbxMesh->GetName())); delete mesh; return 0; } //colors { for (int l=0; l<fbxMesh->GetElementVertexColorCount(); l++) { FbxGeometryElementVertexColor* vertColor = fbxMesh->GetElementVertexColor(l); //CC can only handle per-vertex colors if (vertColor->GetMappingMode() == FbxGeometryElement::eByControlPoint) { if (vertColor->GetReferenceMode() == FbxGeometryElement::eDirect || vertColor->GetReferenceMode() == FbxGeometryElement::eIndexToDirect) { if (vertices->reserveTheRGBTable()) { switch (vertColor->GetReferenceMode()) { case FbxGeometryElement::eDirect: { for (int i=0; i<vertCount; ++i) { FbxColor c = vertColor->GetDirectArray().GetAt(i); vertices->addRGBColor( static_cast<colorType>(c.mRed * MAX_COLOR_COMP), static_cast<colorType>(c.mGreen * MAX_COLOR_COMP), static_cast<colorType>(c.mBlue * MAX_COLOR_COMP) ); } } break; case FbxGeometryElement::eIndexToDirect: { for (int i=0; i<vertCount; ++i) { int id = vertColor->GetIndexArray().GetAt(i); FbxColor c = vertColor->GetDirectArray().GetAt(id); vertices->addRGBColor( static_cast<colorType>(c.mRed * MAX_COLOR_COMP), static_cast<colorType>(c.mGreen * MAX_COLOR_COMP), static_cast<colorType>(c.mBlue * MAX_COLOR_COMP) ); } } break; default: assert(false); break; } vertices->showColors(true); mesh->showColors(true); break; //no need to look for other color fields (we won't be able to handle them! } else { ccLog::Warning(QString("[FBX] Not enough memory to load mesh '%1' colors!").arg(fbxMesh->GetName())); } } else { ccLog::Warning(QString("[FBX] Color field #%i of mesh '%1' will be ignored (unhandled type)").arg(l).arg(fbxMesh->GetName())); } } else { ccLog::Warning(QString("[FBX] Color field #%i of mesh '%1' will be ignored (unhandled type)").arg(l).arg(fbxMesh->GetName())); } } } //normals can be per vertices or per-triangle int perPointNormals = -1; int perVertexNormals = -1; int perPolygonNormals = -1; { for (int j=0; j<fbxMesh->GetElementNormalCount(); j++) { FbxGeometryElementNormal* leNormals = fbxMesh->GetElementNormal(j); switch(leNormals->GetMappingMode()) { case FbxGeometryElement::eByControlPoint: perPointNormals = j; break; case FbxGeometryElement::eByPolygonVertex: perVertexNormals = j; break; case FbxGeometryElement::eByPolygon: perPolygonNormals = j; break; default: //not handled break; } } } //per-point normals if (perPointNormals >= 0) { FbxGeometryElementNormal* leNormals = fbxMesh->GetElementNormal(perPointNormals); FbxLayerElement::EReferenceMode refMode = leNormals->GetReferenceMode(); const FbxLayerElementArrayTemplate<FbxVector4>& normals = leNormals->GetDirectArray(); assert(normals.GetCount() == vertCount); if (normals.GetCount() != vertCount) { ccLog::Warning(QString("[FBX] Wrong number of normals on mesh '%1'!").arg(fbxMesh->GetName())); perPointNormals = -1; } else if (!vertices->reserveTheNormsTable()) { ccLog::Warning(QString("[FBX] Not enough memory to load mesh '%1' normals!").arg(fbxMesh->GetName())); perPointNormals = -1; } else { //import normals for (int i=0; i<vertCount; ++i) { int id = refMode != FbxGeometryElement::eDirect ? leNormals->GetIndexArray().GetAt(i) : i; FbxVector4 N = normals.GetAt(id); //convert to CC-structure CCVector3 Npc( static_cast<PointCoordinateType>(N.Buffer()[0]), static_cast<PointCoordinateType>(N.Buffer()[1]), static_cast<PointCoordinateType>(N.Buffer()[2]) ); vertices->addNorm(Npc.u); } vertices->showNormals(true); mesh->showNormals(true); //no need to import the other normals (if any) perVertexNormals = -1; perPolygonNormals = -1; } } //per-triangle normals NormsIndexesTableType* normsTable = 0; if (perVertexNormals >= 0 || perPolygonNormals >= 0) { normsTable = new NormsIndexesTableType(); if (!normsTable->reserve(polyVertCount) || !mesh->reservePerTriangleNormalIndexes()) { ccLog::Warning(QString("[FBX] Not enough memory to load mesh '%1' normals!").arg(fbxMesh->GetName())); normsTable->release(); normsTable = 0; } else { mesh->setTriNormsTable(normsTable); mesh->addChild(normsTable); vertices->showNormals(true); mesh->showNormals(true); } } //import textures UV int perVertexUV = -1; bool hasTexUV = false; { for (int l=0; l<fbxMesh->GetElementUVCount(); ++l) { FbxGeometryElementUV* leUV = fbxMesh->GetElementUV(l); //per-point UV coordinates if (leUV->GetMappingMode() == FbxGeometryElement::eByControlPoint) { TextureCoordsContainer* vertTexUVTable = new TextureCoordsContainer(); if (!vertTexUVTable->reserve(vertCount) || !mesh->reservePerTriangleTexCoordIndexes()) { vertTexUVTable->release(); ccLog::Warning(QString("[FBX] Not enough memory to load mesh '%1' UV coordinates!").arg(fbxMesh->GetName())); } else { FbxLayerElement::EReferenceMode refMode = leUV->GetReferenceMode(); for (int i=0; i<vertCount; ++i) { int id = refMode != FbxGeometryElement::eDirect ? leUV->GetIndexArray().GetAt(i) : i; FbxVector2 uv = leUV->GetDirectArray().GetAt(id); //convert to CC-structure float uvf[2] = {static_cast<float>(uv.Buffer()[0]), static_cast<float>(uv.Buffer()[1])}; vertTexUVTable->addElement(uvf); } mesh->addChild(vertTexUVTable); hasTexUV = true; } perVertexUV = -1; break; //no need to look to the other UV fields (can't handle them!) } else if (leUV->GetMappingMode() == FbxGeometryElement::eByPolygonVertex) { //per-vertex UV coordinates perVertexUV = l; } } } //per-vertex UV coordinates TextureCoordsContainer* texUVTable = 0; if (perVertexUV >= 0) { texUVTable = new TextureCoordsContainer(); if (!texUVTable->reserve(polyVertCount) || !mesh->reservePerTriangleTexCoordIndexes()) { texUVTable->release(); ccLog::Warning(QString("[FBX] Not enough memory to load mesh '%1' UV coordinates!").arg(fbxMesh->GetName())); } else { mesh->addChild(texUVTable); hasTexUV = true; } } //import polygons { for (int i=0; i<polyCount; ++i) { int pSize = fbxMesh->GetPolygonSize(i); if (pSize > 4) { //not handled for the moment continue; } //we split quads into two triangles //vertex indices int i1 = fbxMesh->GetPolygonVertex(i, 0); int i2 = fbxMesh->GetPolygonVertex(i, 1); int i3 = fbxMesh->GetPolygonVertex(i, 2); mesh->addTriangle(i1,i2,i3); int i4 = -1; if (pSize == 4) { i4 = fbxMesh->GetPolygonVertex(i, 3); mesh->addTriangle(i1,i3,i4); } if (hasTexUV) { if (texUVTable) { assert(perVertexUV >= 0); int uvIndex = static_cast<int>(texUVTable->currentSize()); for (int j=0; j<pSize; ++j) { int lTextureUVIndex = fbxMesh->GetTextureUVIndex(i, j); FbxGeometryElementUV* leUV = fbxMesh->GetElementUV(perVertexUV); FbxVector2 uv = leUV->GetDirectArray().GetAt(lTextureUVIndex); //convert to CC-structure float uvf[2] = {static_cast<float>(uv.Buffer()[0]), static_cast<float>(uv.Buffer()[1])}; texUVTable->addElement(uvf); } mesh->addTriangleTexCoordIndexes(uvIndex,uvIndex+1,uvIndex+2); if (pSize == 4) mesh->addTriangleTexCoordIndexes(uvIndex,uvIndex+2,uvIndex+3); } else { mesh->addTriangleTexCoordIndexes(i1,i2,i3); if (pSize == 4) mesh->addTriangleTexCoordIndexes(i1,i3,i4); } } //per-triangle normals if (normsTable) { int nIndex = static_cast<int>(normsTable->currentSize()); for (int j=0; j<pSize; ++j) { FbxVector4 N; fbxMesh->GetPolygonVertexNormal(i, j, N); CCVector3 Npc( static_cast<PointCoordinateType>(N.Buffer()[0]), static_cast<PointCoordinateType>(N.Buffer()[1]), static_cast<PointCoordinateType>(N.Buffer()[2]) ); normsTable->addElement(ccNormalVectors::GetNormIndex(Npc.u)); } mesh->addTriangleNormalIndexes(nIndex,nIndex+1,nIndex+2); if (pSize == 4) mesh->addTriangleNormalIndexes(nIndex,nIndex+2,nIndex+3); } } if (mesh->size() == 0) { ccLog::Warning(QString("[FBX] No triangle found in mesh '%1'! (only triangles are supported for the moment)").arg(fbxMesh->GetName())); delete mesh; return 0; } } //import vertices { const FbxVector4* fbxVertices = fbxMesh->GetControlPoints(); assert(vertices && fbxVertices); CCVector3d Pshift(0,0,0); for (int i=0; i<vertCount; ++i, ++fbxVertices) { const double* P = fbxVertices->Buffer(); assert(P[3] == 0); //coordinate shift management if (i == 0) { bool shiftAlreadyEnabled = (coordinatesShiftEnabled && *coordinatesShiftEnabled && coordinatesShift); if (shiftAlreadyEnabled) Pshift = *coordinatesShift; bool applyAll = false; if ( sizeof(PointCoordinateType) < 8 && ccCoordinatesShiftManager::Handle(P,0,alwaysDisplayLoadDialog,shiftAlreadyEnabled,Pshift,0,applyAll)) { vertices->setGlobalShift(Pshift); ccLog::Warning("[FBX] Mesh has been recentered! Translation: (%.2f,%.2f,%.2f)",Pshift.x,Pshift.y,Pshift.z); //we save coordinates shift information if (applyAll && coordinatesShiftEnabled && coordinatesShift) { *coordinatesShiftEnabled = true; *coordinatesShift = Pshift; } } } CCVector3 PV( static_cast<PointCoordinateType>(P[0] + Pshift.x), static_cast<PointCoordinateType>(P[1] + Pshift.y), static_cast<PointCoordinateType>(P[2] + Pshift.z) ); vertices->addPoint(PV); } } //import textures { //TODO } return mesh; }
PV pvBase() const { return PV(rgl); }
int calc_hydrogen_bond_force(Particle *s1, Particle *b1, Particle *b2, Particle *s2, Bonded_ia_parameters *iaparams, double f_s1[3], double f_b1[3], double f_b2[3], double f_s2[3]) { /* Base-Base and Sugar-Sugar vectors */ double rhb[3], rcc[3]; /* Sugar-Base Vectors */ double rcb1[3], rcb2[3], rcb1_l, rcb2_l; /* Normal vectors of the base pairs */ double n1[3], n2[3]; /* Dihedral of the base pair */ double gammad; /* Base angles */ double psi1, psi2; double dpsi1, dpsi2; /* gamma1 = cos(psi1) */ /* length of rhb */ double gamma1, gamma2; double rhb_l, rcc_l; /* magnitude of the _r contribution to the force */ double f_r; double f_d; double f_f1, f_f2; double f_sb1, f_sb2; /* helper variables */ double ra, temp, tau_r, tau_d, tau_flip, tau_rd; const Bonded_ia_parameters params = *iaparams; const double E0 = params.p.hydrogen_bond.E0; #ifdef CG_DNA_DEBUG // puts("calc_hydrogen_bond_force():"); #endif /* Calculate geometry variables */ get_mi_vector(rcc, s2->r.p, s1->r.p); get_mi_vector(rhb, b2->r.p, b1->r.p); get_mi_vector(rcb1, b1->r.p, s1->r.p); get_mi_vector(rcb2, b2->r.p, s2->r.p); rcb1_l = norm(rcb1); rcb2_l = norm(rcb2); rcc_l = norm(rcc); cross(rcc, rcb1, n1); cross(rcc, rcb2, n2); const double n1_l = norm(n1); const double n2_l = norm(n2); rhb_l = norm(rhb); /* Sugar base interaction */ const double r0sb = params.p.hydrogen_bond.r0sb; const double alphasb = params.p.hydrogen_bond.alphasb; const double f2 = params.p.hydrogen_bond.f2; const double f3 = params.p.hydrogen_bond.f3; const double E0sb = params.p.hydrogen_bond.E0sb; const double c0sb = (1. - 2.*f2)*E0sb*alphasb; const double c1sb = (f2-3.*f3)*E0sb*alphasb; const double c2sb = f3*E0sb*alphasb; ra = (rcb1_l - r0sb)*alphasb; f_sb1 = exp(-ra)*ra*(c0sb+c1sb*ra+c2sb*ra*ra)/rcb1_l; ra = (rcb2_l - r0sb)*alphasb; f_sb2 = exp(-ra)*ra*(c0sb+c1sb*ra+c2sb*ra*ra)/rcb2_l; /* Hydrogen bond interaction */ /* Radial part */ ra = (rhb_l - params.p.hydrogen_bond.r0)*params.p.hydrogen_bond.alpha; temp = exp(-ra); tau_r = temp *(1.+ra); f_r = E0*params.p.hydrogen_bond.alpha*temp*ra/rhb_l; /* Dihedral part */ gammad = dot(n1, n2)/(n1_l*n2_l); tau_d = exp(params.p.hydrogen_bond.kd*(gammad - 1)); f_d = -E0*params.p.hydrogen_bond.kd*tau_d/(n1_l*n2_l); /* Flip part */ gamma1 = dot(rcc, rcb1)/(rcc_l*rcb1_l); gamma2 = -dot(rcc, rcb2)/(rcc_l*rcb2_l); /* Avoid illdefined values */ if((gamma1 > COS_MAX) || (gamma1 < COS_MIN)) { gamma1 = (gamma1 > COS_MAX)? COS_MAX : COS_MIN; } if((gamma2 > COS_MAX) || (gamma2 < COS_MIN)) gamma2 = (gamma2 > COS_MAX)? COS_MAX : COS_MIN; psi1 = gamma1 >= 1. ? 0. : (gamma1 <= -1. ? M_PI : acos(gamma1)); psi2 = gamma2 >= 1. ? 0. : (gamma2 <= -1. ? M_PI : acos(gamma2)); dpsi1 = psi1 - params.p.hydrogen_bond.psi10; dpsi2 = psi2 - params.p.hydrogen_bond.psi20; const double sigma1sqr = (SQR(params.p.hydrogen_bond.sigma1)); const double sigma2sqr = (SQR(params.p.hydrogen_bond.sigma2)); f_f1 = -dpsi1 / sqrt(1. - SQR(gamma1)) * params.p.hydrogen_bond.E0/sigma1sqr; f_f2 = -dpsi2 / sqrt(1. - SQR(gamma2)) * params.p.hydrogen_bond.E0/sigma2sqr; tau_rd = tau_r * tau_d; if(dpsi1 > 0 && dpsi2 > 0) { tau_flip = exp(-(SQR(dpsi1)/(2.*sigma1sqr)+ SQR(dpsi2)/(2.*sigma2sqr))); f_f1 *= tau_flip * tau_rd; f_f2 *= tau_flip * tau_rd; } else if (dpsi1 > 0.) { tau_flip = exp(-(SQR(dpsi1)/(2.*sigma1sqr))); f_f1 *= tau_flip * tau_rd; } else if (dpsi2 > 0.) { tau_flip = exp(-(SQR(dpsi2)/(2.*sigma2sqr))); f_f2 *= tau_flip * tau_rd; } else { tau_flip = 1.; } /* Angle at which the constraint sets in */ const double psi_cutoff = PI*140./180.; /* Spring constant for the angle constraint */ const double k_constraint = 50.; if(psi1 > psi_cutoff) { f_f1 += k_constraint*(psi1-psi_cutoff)/sqrt(1. - SQR(gamma1)); } if(psi2 > psi_cutoff) { f_f2 += k_constraint*(psi2-psi_cutoff)/sqrt(1. - SQR(gamma2)); } f_r *= tau_d*tau_flip; f_d *= tau_r*tau_flip; /* Dihedral force */ double vec[3]; cross(n1, n2, vec); const double dot1 = f_d * dot(vec, rcc); const double dot2 = f_d * dot(vec, rcb1); const double dot3 = f_d * dot(vec, rcb2); const double dot4 = dot2 - dot1; const double dot5 = dot1 + dot3; const double factor1 = f_f1/(rcc_l * rcb1_l); const double factor2 = f_f1*gamma1/SQR(rcb1_l); const double factor3 = f_f1*gamma1/SQR(rcc_l); const double factor4 = f_f2/(rcc_l * rcb2_l); const double factor5 = f_f2*gamma2/SQR(rcb2_l); const double factor6 = f_f2*gamma2/SQR(rcc_l); double fBase1, fSugar2, fBase2, fSugar1; double fr, n1n, n2n; #ifdef CG_DNA_DEBUG int big_force = 0; #endif for(int i = 0; i < 3; i++) { fr = f_r * rhb[i]; n1n = n1[i]/n1_l; n2n = n2[i]/n2_l; fBase1 = factor1*rcc[i] - factor2 * rcb1[i]; fSugar2 = factor1*rcb1[i] - factor3 * rcc[i]; fBase2 = -factor4*rcc[i] - factor5 * rcb2[i]; fSugar1 = factor4*rcb2[i] + factor6 * rcc[i]; f_b1[i] = -fr + dot1*n1n + fBase1 + f_sb1 *rcb1[i]; f_b2[i] = fr - dot1*n2n + fBase2 + f_sb2 *rcb2[i]; f_s1[i] = dot4*n1n - dot3*n2n + fSugar1 - fBase1 - fSugar2 - f_sb1 *rcb1[i]; f_s2[i] = dot5*n2n - dot2*n1n + fSugar2 - fBase2 - fSugar1 - f_sb2 *rcb2[i]; #ifdef CG_DNA_DEBUG if((f_b1[i] >= 100.) || (f_b2[i] >= 100.) || (f_s1[i] >= 100.) || (f_s2[i] >= 100.)) big_force = 1; #endif } #ifdef CG_DNA_DEBUG if(big_force) { puts("Big Force Basepair."); PS(s1->p.identity); PS(b1->p.identity); PS(b2->p.identity); PS(s2->p.identity); PV(s1->r.p); PV(b1->r.p); PV(b2->r.p); PV(s2->r.p); PV(rhb); PV(rcc); PV(rcb1); PV(rcb2); PS(rhb_l); PS(rcc_l); PS(rcb1_l); PS(rcb2_l); PS(gamma1); PS(gamma2); PS(dot(n1,n2)); PV(n1); PV(n2); PV(dot1*n1); PV(dot2*n2); PV(f_sb1 *rcb1); PV(f_sb2 *rcb2); PV(f_r*rhb); PS(f_r); PS(f_r*rhb_l); PS(f_sb1); PS(f_sb2); PS(tau_d); PS(tau_r); PS(tau_flip); PS(dot1); PS(dot2); PS(dot3); PS(dot4); PS(dot5); PS(factor1); PS(factor2); PS(factor3); PS(factor4); PS(factor5); PS(factor6); PS(fSugar1); PS(fBase1); PS(fBase2); PS(fSugar2); PV(f_s1); PV(f_b1); PV(f_b2); PV(f_s2); } #endif return 0; }
void baz() { void *t; PV(&baz, t); }