//-***************************************************************************** void MeshDrwHelper::update( P3fArraySamplePtr iP, V3fArraySamplePtr iN, Abc::Box3d iBounds ) { // Check validity. if ( !m_valid || !iP || !m_meshP || ( iP->size() != m_meshP->size() ) ) { makeInvalid(); return; } // Set meshP m_meshP = iP; if ( iBounds.isEmpty() ) { computeBounds(); } else { m_bounds = iBounds; } updateNormals( iN ); }
void Socket::Listen() { if (!checkValid("Socket::Listen")) { return; } if (listen(sock, SOMAXCONN)) { makeInvalid("listen"); } }
void Socket::makeNonBlocking() { if (!checkValid("Socket::makeNonBlocking")) { return; } int flags, s; flags = fcntl(sock, F_GETFL, 0); if (flags == -1) { return makeInvalid("fcntl"); } flags |= O_NONBLOCK; s = fcntl(sock, F_SETFL, flags); if (s == -1) { return makeInvalid("fcntl"); } }
//-***************************************************************************** void MeshDrwHelper::updateNormals( V3fArraySamplePtr iN ) { if ( !m_valid || !m_meshP ) { makeInvalid(); return; } //std::cout << "normals - " << m_name << std::endl; // Now see if we need to calculate normals. if ( ( m_meshN && iN == m_meshN ) )//|| // ( !iN && m_customN.size() > 0 ) ) { return; } size_t numPoints = m_meshP->size(); m_meshN = iN; m_customN.clear(); // Right now we only handle "vertex varying" normals, // which have the same cardinality as the points if ( !m_meshN || m_meshN->size() != numPoints ) { // Make some custom normals. m_meshN.reset(); m_customN.resize( numPoints ); std::fill( m_customN.begin(), m_customN.end(), V3f( 0.0f ) ); //std::cout << "Recalcing normals for object: " // << m_host.name() << std::endl; for ( size_t tidx = 0; tidx < m_triangles.size(); ++tidx ) { const Tri &tri = m_triangles[tidx]; const V3f &A = (*m_meshP)[tri[0]]; const V3f &B = (*m_meshP)[tri[1]]; const V3f &C = (*m_meshP)[tri[2]]; V3f AB = B - A; V3f AC = C - A; V3f wN = AB.cross( AC ); m_customN[tri[0]] += wN; m_customN[tri[1]] += wN; m_customN[tri[2]] += wN; } // Normalize normals. for ( size_t nidx = 0; nidx < numPoints; ++nidx ) { m_customN[nidx].normalize(); } } }
void Socket::Close() { if (!checkValid("Close")) { return; } int err = close(sock); if (err < 0) { makeInvalid("close"); } }
void MgClKernel::tryCreateKernel() { if(environment() && environment()->programBuildStatus() == MgClEnvironment::BuildSucces) { cl_int error; d_ptr->kernel = cl::Kernel (d_ptr->environment->d_ptr->program,qPrintable(name()),&error); if(error != CL_SUCCESS) { makeInvalid(); } else setValid(true); } else { makeInvalid(); } }
void Socket::Connect(const sockaddr *addr, socklen_t addrlen) { if (!checkValid("Socket::Connect")) { return; } int err = connect(sock, addr, addrlen); if (err < 0) { makeInvalid("connect"); } }
void Socket::Socket_(int domain, int type, int protocol) { if (!checkValid("Socket::Socket_")) { return; } sock = socket(domain, type, protocol); if (sock < 0) { Utility::info("socket"); makeInvalid("Socket_"); } }
bool Socket::Bind(const sockaddr *addr, socklen_t addrlen) { if (!checkValid("Socket::Bind")) { return false; } int res = bind(sock, addr, addrlen); if (res != 0) { makeInvalid("bind"); } return res == 0; }
//-***************************************************************************** void MeshDrwHelper::update( V3fArraySamplePtr iP, V3fArraySamplePtr iN ) { // Check validity. if ( !m_valid || !iP || !m_meshP || ( iP->size() != m_meshP->size() ) ) { makeInvalid(); return; } // Set meshP m_meshP = iP; computeBounds(); updateNormals( iN ); }
Marker::Marker(Diagram *Diag_, Graph *pg_, int _nn, int cx_, int cy_) { Type = isMarker; isSelected = transparent = false; Diag = Diag_; pGraph = pg_; Precision = 3; // before createText() numMode = nVarPos = 0; cx = cx_; cy = -cy_; if(!pGraph) makeInvalid(); else initText(_nn); // finally create marker x1 = cx + 60; y1 = -cy - 60; }
void SphereClumpGeom::recompute(int _div, bool failOk, bool fastOnly){ if((centers.empty() && radii.empty()) || centers.size()!=radii.size()){ if(failOk) { makeInvalid(); return;} throw std::runtime_error("SphereClumpGeom.recompute: centers and radii must have the same length (len(centers)="+to_string(centers.size())+", len(radii)="+to_string(radii.size())+"), and may not be empty."); } div=_div; // one single sphere: simple if(centers.size()==1){ pos=centers[0]; ori=Quaternionr::Identity(); volume=(4/3.)*M_PI*pow(radii[0],3); inertia=Vector3r::Constant((2/5.)*volume*pow(radii[0],2)); equivRad=radii[0]; return; } volume=0; Vector3r Sg=Vector3r::Zero(); Matrix3r Ig=Matrix3r::Zero(); if(_div<=0){ // non-intersecting: Steiner's theorem for(size_t i=0; i<centers.size(); i++){ const Real& r(radii[i]); const Vector3r& x(centers[i]); Real v=(4/3.)*M_PI*pow(r,3); volume+=v; Sg+=v*x; Ig+=woo::Volumetric::inertiaTensorTranslate(Vector3r::Constant((2/5.)*v*pow(r,2)).asDiagonal(),v,-1.*x); } } else { // intersecting: grid sampling Real rMin=Inf; AlignedBox3r aabb; for(size_t i=0; i<centers.size(); i++){ aabb.extend(centers[i]+Vector3r::Constant(radii[i])); aabb.extend(centers[i]-Vector3r::Constant(radii[i])); rMin=min(rMin,radii[i]); } if(rMin<=0){ if(failOk){ makeInvalid(); return; } throw std::runtime_error("SphereClumpGeom.recompute: minimum radius must be positive (not "+to_string(rMin)+")"); } Real dx=rMin/_div; Real dv=pow(dx,3); long nCellsApprox=(aabb.sizes()/dx).prod(); // don't compute anything, it would take too long if(fastOnly && nCellsApprox>1e5){ makeInvalid(); return; } if(nCellsApprox>1e8) LOG_WARN("SphereClumpGeom: space grid has "<<nCellsApprox<<" cells, computing inertia can take a long time."); Vector3r x; for(x.x()=aabb.min().x()+dx/2.; x.x()<aabb.max().x(); x.x()+=dx){ for(x.y()=aabb.min().y()+dx/2.; x.y()<aabb.max().y(); x.y()+=dx){ for(x.z()=aabb.min().z()+dx/2.; x.z()<aabb.max().z(); x.z()+=dx){ for(size_t i=0; i<centers.size(); i++){ if((x-centers[i]).squaredNorm()<pow(radii[i],2)){ volume+=dv; Sg+=dv*x; Ig+=dv*(x.dot(x)*Matrix3r::Identity()-x*x.transpose())+/*along princial axes of dv; perhaps negligible?*/Matrix3r(Vector3r::Constant(dv*pow(dx,2)/6.).asDiagonal()); break; } } } } } } woo::Volumetric::computePrincipalAxes(volume,Sg,Ig,pos,ori,inertia); equivRad=(inertia.array()/volume).sqrt().mean(); // mean of radii of gyration }
JsonHashTable::JsonHashTable(char* json, jsmntok_t* tokens) : JsonObjectBase(json, tokens) { if (tokens[0].type != JSMN_OBJECT) makeInvalid(); }
//-***************************************************************************** void MeshDrwHelper::update( P3fArraySamplePtr iP, V3fArraySamplePtr iN, Int32ArraySamplePtr iIndices, Int32ArraySamplePtr iCounts, Abc::Box3d iBounds ) { // Before doing a ton, just have a quick look. if ( m_meshP && iP && ( m_meshP->size() == iP->size() ) && m_meshIndices && ( m_meshIndices == iIndices ) && m_meshCounts && ( m_meshCounts == iCounts ) ) { if ( m_meshP == iP ) { updateNormals( iN ); } else { update( iP, iN ); } return; } // Okay, if we're here, the indices are not equal or the counts // are not equal or the P-array size changed. // So we can clobber those three, but leave N alone for now. m_meshP = iP; m_meshIndices = iIndices; m_meshCounts = iCounts; m_triangles.clear (); // Check stuff. if ( !m_meshP || !m_meshIndices || !m_meshCounts ) { std::cerr << "Mesh update quitting because no input data" << std::endl; makeInvalid(); return; } // Get the number of each thing. size_t numFaces = m_meshCounts->size(); size_t numIndices = m_meshIndices->size(); size_t numPoints = m_meshP->size(); if ( numFaces < 1 || numIndices < 1 || numPoints < 1 ) { // Invalid. std::cerr << "Mesh update quitting because bad arrays" << ", numFaces = " << numFaces << ", numIndices = " << numIndices << ", numPoints = " << numPoints << std::endl; makeInvalid(); return; } // Make triangles. size_t faceIndexBegin = 0; size_t faceIndexEnd = 0; for ( size_t face = 0; face < numFaces; ++face ) { faceIndexBegin = faceIndexEnd; size_t count = (*m_meshCounts)[face]; faceIndexEnd = faceIndexBegin + count; // Check this face is valid if ( faceIndexEnd > numIndices || faceIndexEnd < faceIndexBegin ) { std::cerr << "Mesh update quitting on face: " << face << " because of wonky numbers" << ", faceIndexBegin = " << faceIndexBegin << ", faceIndexEnd = " << faceIndexEnd << ", numIndices = " << numIndices << ", count = " << count << std::endl; // Just get out, make no more triangles. break; } // Checking indices are valid. bool goodFace = true; for ( size_t fidx = faceIndexBegin; fidx < faceIndexEnd; ++fidx ) { if ( ( size_t ) ( (*m_meshIndices)[fidx] ) >= numPoints ) { std::cout << "Mesh update quitting on face: " << face << " because of bad indices" << ", indexIndex = " << fidx << ", vertexIndex = " << (*m_meshIndices)[fidx] << ", numPoints = " << numPoints << std::endl; goodFace = false; break; } } // Make triangles to fill this face. if ( goodFace && count > 2 ) { m_triangles.push_back( Tri( ( unsigned int )(*m_meshIndices)[faceIndexBegin+0], ( unsigned int )(*m_meshIndices)[faceIndexBegin+1], ( unsigned int )(*m_meshIndices)[faceIndexBegin+2] ) ); for ( size_t c = 3; c < count; ++c ) { m_triangles.push_back( Tri( ( unsigned int )(*m_meshIndices)[faceIndexBegin+0], ( unsigned int )(*m_meshIndices)[faceIndexBegin+c-1], ( unsigned int )(*m_meshIndices)[faceIndexBegin+c] ) ); } } } // Cool, we made triangles. // Pretend the mesh is made... m_valid = true; // And now update just the P and N, which will update bounds // and calculate new normals if necessary. if ( iBounds.isEmpty() ) { computeBounds(); } else { m_bounds = iBounds; } updateNormals( iN ); // And that's it. }
//-***************************************************************************** MeshDrwHelper::~MeshDrwHelper() { makeInvalid(); }
JsonArray::JsonArray(char* json, jsmntok_t* tokens) : JsonObjectBase(json, tokens) { if (tokens[0].type != JSMN_ARRAY) makeInvalid(); }
// --------------------------------------------------------------------- void Marker::initText(int n) { if(pGraph->cPointsX.isEmpty()) { makeInvalid(); return; } Axis *pa; if(pGraph->yAxisNo == 0) pa = &(Diag->yAxis); else pa = &(Diag->zAxis); double *px, *py=0, *pz; Text = ""; nVarPos = 0; bool isCross = false; int nn, nnn, m, x, y, d, dmin = INT_MAX; DataX *pD = pGraph->cPointsX.first(); px = pD->Points; nnn = pD->count; DataX *pDy = pGraph->cPointsX.next(); if(pDy) { // only for 3D diagram nn = pGraph->countY * pD->count; py = pDy->Points; if(n >= nn) { // is on cross grid ? isCross = true; n -= nn; n /= nnn; px += (n % nnn); if(pGraph->cPointsX.next()) // more than 2 indep variables ? n = (n % nnn) + (n / nnn) * nnn * pDy->count; nnn = pDy->count; } else py += (n/pD->count) % pDy->count; } // find exact marker position m = nnn - 1; pz = pGraph->cPointsY + 2*n; for(nn=0; nn<nnn; nn++) { Diag->calcCoordinate(px, pz, py, &x, &y, pa); if(isCross) { px--; py++; pz += 2*(pD->count-1); } x -= cx; y -= cy; d = x*x + y*y; if(d < dmin) { dmin = d; m = nn; } } if(isCross) m *= pD->count; n += m; // gather text of all independent variables nn = n; for(pD = pGraph->cPointsX.first(); pD!=0; pD = pGraph->cPointsX.next()) { px = pD->Points + (nn % pD->count); VarPos[nVarPos++] = *px; Text += pD->Var + ": " + QString::number(*px,'g',Precision) + "\n"; nn /= pD->count; } // gather text of dependent variable pz = (pGraph->cPointsY) + 2*n; Text += pGraph->Var + ": "; switch(numMode) { case 0: Text += complexRect(*pz, *(pz+1), Precision); break; case 1: Text += complexDeg(*pz, *(pz+1), Precision); break; case 2: Text += complexRad(*pz, *(pz+1), Precision); break; } VarPos[nVarPos] = *pz; VarPos[nVarPos+1] = *(pz+1); px = VarPos; py = VarPos + 1; Diag->calcCoordinate(px, pz, py, &cx, &cy, pa); if(!Diag->insideDiagram(cx, cy)) // if marker out of valid bounds, point to origin if((Diag->Name.left(4) != "Rect") && (Diag->Name != "Curve")) { cx = Diag->x2 >> 1; cy = Diag->y2 >> 1; }