unsigned long UnaryOpRep::dagSize() { if (!visited()) { visited() = true; numNodes() = child->dagSize() + 1; } else numNodes() = 0; return numNodes(); }
unsigned long ConstRep::dagSize() { if (!visited()) { visited() = true; numNodes() = 1; } else numNodes() = 0; return numNodes(); }
unsigned long BinOpRep::dagSize() { if (!visited()) { visited() = true; numNodes() = first->dagSize() + second->dagSize() + 1; } else numNodes() = 0; return numNodes(); }
int numNodes(BusinessTree *n) { int c = 1; if (n == NULL) return 0; else { c += numNodes(n->left); c += numNodes(n->right); return c; } }
int numNodes(TreeNode n) { int nnodes = 0; if (n == NULL){ nnodes = 0; } else{ int lnnodes = numNodes(n->leftnode); int rnnodes = numNodes(n->rightnode); nnodes = 1 + lnnodes + rnnodes; } return nnodes; }
int numNodes(WordData *n) { int c = 1; if (n == NULL) { return 0; } else { c += numNodes(n->left); c += numNodes(n->right); } return c; }
// works better if you have key values that are unique for each node TreeNode rebalanceTree(TreeNode t) { if (t == NULL){ return NULL; } if (numNodes(t) < 2){ // no need to rebalance return t; } t = partition(t, numNodes(t)/2); // place the median node as root t->leftnode = rebalanceTree(t->leftnode); t->rightnode = rebalanceTree(t->rightnode); return t; }
// Dijkstra's algorithim for computing shortest path void Graph::computeShortestPaths(int aNodeId) { initializeShortestPath(aNodeId); Heap<Node*> heap(numNodes()); // Insert all the nodes into the heap for (const SLLNode<Node*>* curr = mNodes.head(); curr != NULL; curr = curr->next()) { Node* currNode = curr->value(); heap.insertIgnoringHeapOrder(currNode); } // Heapify into a min heap heap.bottomUpMinHeap(); // You can call heap.removeMin() to extract the min while(!heap.isEmpty()){ Node* u = heap.removeMin(); SLinkedList<Edge*> edges = u->getEdges(); for (SLLNode<Edge*>* curr = edges.head(); curr != NULL; curr = curr->next()){ Edge* e = curr->value(); relax(e); } heap.bottomUpMinHeap(); } }
bool BasicBlock::isInBlock(Node* myNode) const { for (size_t i = 0; i < numNodes(); ++i) { if (node(i) == myNode) return true; } return false; }
// Initialize a new geogram mesh corresponding to the current grid void OctreeGrid::createMesh( GEO::Mesh &mesh, const Eigen::Vector3d &origin, const Eigen::Vector3d &spacing) const { mesh.clear(false, false); // logger_debug("OctreeGrid", "createMesh(): Allocate vertices and cells"); // Create the mesh of regular grid mesh.vertices.create_vertices(numNodes()); for (int idx = 0; idx < numNodes(); ++idx) { Eigen::Vector3d pos = origin + nodePos(idx).cast<double>().cwiseProduct(spacing); mesh.vertices.point(idx) = GEO::vec3(pos[0], pos[1], pos[2]); } // Count num of leaf cells int numLeaves = 0; for (int c = 0; c < numCells(); ++c) { if (cellIsLeaf(c)) { ++numLeaves; } } GEO::index_t firstCube = mesh.cells.create_hexes(numLeaves); for (int q = 0, c = 0; q < numCells(); ++q) { if (!cellIsLeaf(q)) { continue; } Eigen::Vector3i diff[8] = { {0,0,0}, {1,0,0}, {0,1,0}, {1,1,0}, {0,0,1}, {1,0,1}, {0,1,1}, {1,1,1} }; for (GEO::index_t lv = 0; lv < 8; ++lv) { int cornerId = Cube::invDelta(diff[lv]); int v = cellCornerId(q, cornerId); mesh.cells.set_vertex(firstCube + c, lv, v); } ++c; } // logger_debug("OctreeGrid", "createMesh(): Connecting cells"); //GEO::Logger::out("OctreeGrid") << "Computing borders..." << std::endl; //mesh.cells.compute_borders(); //GEO::Logger::out("OctreeGrid") << "Connecting cells..." << std::endl; //mesh.cells.connect(); // logger_debug("OctreeGrid", "createMesh(): Creating attributes..."); updateMeshAttributes(mesh); }
// Traverse the leaf cells recursively and split them according to the predicate function void OctreeGrid::subdivide(std::function<bool(int, int, int, int)> predicate, bool graded, bool paired, int maxCells) { std::queue<int> pending; for (int i = 0; i < (int) m_Cells.size(); ++i) { if (cellIsLeaf(i)) { pending.push(i); } } int numNodesBefore = numNodes(); int numCellsBefore = numCells(); int numSubdivided = 0; if (maxCells < 0) { maxCells = std::numeric_limits<int>::max(); } while (!pending.empty() && numCells() + 8 <= maxCells) { int id = pending.front(); pending.pop(); int extent = cellExtent(id); auto pos = cellCornerPos(id, 0); if (predicate(pos[0], pos[1], pos[2], extent)) { if (extent == 1) { std::cerr << "[OctreeGrid] Cannot subdivide cell of length 1." << std::endl; } else { if (cellIsLeaf(id)) { splitCell(id, graded, paired); } for (int k = 0; k < 8; ++k) { pending.push(m_Cells[id].firstChild + k); } } } } // Resize attribute vectors nodeAttributes.resize(numNodes()); cellAttributes.resize(numCells()); GEO::Logger::out("OctreeGrid") << "Subdivide has split " << numSubdivided << " cells\n"; GEO::Logger::out("OctreeGrid") << "Num nodes: " << numNodesBefore << " -> " << numNodes() << "\n"; GEO::Logger::out("OctreeGrid") << "Num cells: " << numCellsBefore << " -> " << numCells() << std::endl; }
nodeArray newNodeArray(node root) { long N; nodeArray A; N=numNodes(root); A=(nodeArray)malloc(N*sizeof(node)); gix=0; newNodeArrayHelper(A,root); return A; }
unsigned long numNodes(node n) { unsigned long sum=0; node child; child=n->firstdesc; SIBLOOP(child) sum += numNodes(child); /* add one for each child and all that children's*/ return (1+sum); /* the 1 is to count this node, which must be internal */ }
void Project::SetVisibleDomain(Domain *newDomain) { if (newDomain) { visibleDomain = newDomain; if (glPanel) glPanel->SetActiveDomainNew(visibleDomain); Fort14 *currFort14 = visibleDomain->GetFort14(); if (currFort14) { emit numElements(currFort14->GetNumElements()); emit numNodes(currFort14->GetNumNodes()); } emit undoAvailable(visibleDomain->UndoAvailable()); emit redoAvailable(visibleDomain->RedoAvailable()); if (displayOptions && displayOptions->isVisible()) { displayOptions->SetActiveDomain(visibleDomain); displayOptions->update(); } if (projectTree) { if (visibleDomain == fullDomain) projectTree->setCurrentItem(projectTree->findItems("Full Domain", Qt::MatchExactly | Qt::MatchRecursive).first()); else { SubDomain *targetDomain = DetermineSubdomain(visibleDomain); if (targetDomain) { QString name = targetDomain->GetDomainName(); projectTree->setCurrentItem(projectTree->findItems(name, Qt::MatchExactly | Qt::MatchRecursive).first()); } } } if (editSubdomainList) { if (visibleDomain == fullDomain) editSubdomainList->clearSelection(); else { SubDomain *targetDomain = DetermineSubdomain(visibleDomain); if (targetDomain) { QString name = targetDomain->GetDomainName(); editSubdomainList->setCurrentItem(editSubdomainList->findItems(name, Qt::MatchExactly | Qt::MatchRecursive).first()); } } } } }
intrusive_list_base::size_type intrusive_list_base::size() const { size_type numNodes(0); const intrusive_list_node* iter = &m_root; do { iter = iter->next; ++numNodes; } while (iter != &m_root); return numNodes - 1; }
bool BspSceneFile::loadNodes(std::istream& bspStream, const Q3Bsp::DirEntry& nodesEntry) { if (!bspStream.seekg(nodesEntry.offset, std::ios::beg)) { return false; } std::size_t numNodes(nodesEntry.length / sizeof(Q3Bsp::Node)); m_nodes.reserve(numNodes); if (!bspStream.read(reinterpret_cast<char*>(&m_nodes[0]), nodesEntry.length)) { return false; } return true; }
//! @brief Return the element resisting force. const XC::Vector &XC::FourNodeQuad::getResistingForce(void) const { P.Zero(); double dvol; // Loop over the integration points for(size_t i= 0;i<physicalProperties.size();i++) { // Determine Jacobian for this integration point const GaussPoint &gp= getGaussModel().getGaussPoints()[i]; dvol= this->shapeFunction(gp); dvol*= (physicalProperties.getThickness()*gp.weight()); // Get material stress response const Vector &sigma = physicalProperties[i]->getStress(); // Perform numerical integration on internal force //P = P + (B^ sigma) * intWt(i)*intWt(j) * detJ; //P.addMatrixTransposeVector(1.0, B, sigma, intWt(i)*intWt(j)*detJ); for(int alpha = 0,ia = 0;alpha<numNodes(); alpha++,ia += 2) { P(ia)+= dvol*(shp[0][alpha]*sigma(0) + shp[1][alpha]*sigma(2)); P(ia+1)+= dvol*(shp[1][alpha]*sigma(1) + shp[0][alpha]*sigma(2)); // Subtract equiv. body forces from the nodes //P = P - (N^ b) * intWt(i)*intWt(j) * detJ; //P.addMatrixTransposeVector(1.0, N, b, -intWt(i)*intWt(j)*detJ); P(ia)-= dvol*(shp[2][alpha]*bf[0]); P(ia+1)-= dvol*(shp[2][alpha]*bf[1]); } } // Subtract pressure loading from resisting force if(pressure != 0.0) { //P = P - pressureLoad; P.addVector(1.0, pressureLoad, -1.0); } // Subtract other external nodal loads ... P_res = P_int - P_ext //P = P - load; P.addVector(1.0, load, -1.0); if(isDead()) P*=dead_srf; return P; }
//! @brief Prints element information. void XC::FourNodeQuad::Print(std::ostream &s, int flag) { if(flag == 2) { s << "#FourNodeQuad\n"; //const int numNodes = 4; const int nstress = 3 ; for(int i=0; i<numNodes(); i++) { const XC::Vector &nodeCrd = theNodes[i]->getCrds(); //const XC::Vector &nodeDisp = theNodes[i]->getDisp(); s << "#NODE " << nodeCrd(0) << " " << nodeCrd(1) << " " << std::endl; } // spit out the section location & invoke print on the scetion static const Vector &avgStress= physicalProperties.getCommittedAvgStress(); static const Vector &avgStrain= physicalProperties.getCommittedAvgStrain(); s << "#AVERAGE_STRESS "; for(int i=0; i<nstress; i++) s << avgStress(i) << " " ; s << std::endl; s << "#AVERAGE_STRAIN "; for(int i=0;i<nstress; i++) s << avgStrain(i) << " " ; s << std::endl; } else { s << "\nFourNodeQuad, element id: " << this->getTag() << std::endl; s << "\tConnected external nodes: " << theNodes; s << "\tphysicalProperties.getThickness(): " << physicalProperties.getThickness() << std::endl; s << "\tmass density: " << physicalProperties.getRho() << std::endl; s << "\tsurface pressure: " << pressure << std::endl; s << "\tbody forces: " << bf << std::endl; physicalProperties.Print(s,flag); s << "\tStress (xx yy xy)" << std::endl; for(size_t i = 0; i < physicalProperties.size(); i++) s << "\t\tGauss point " << i+1 << ": " << physicalProperties[i]->getStress(); } }
//! @brief Adds inertia loads. int XC::FourNodeQuad::addInertiaLoadToUnbalance(const XC::Vector &accel) { static Vector rhoi(4); rhoi= physicalProperties.getRhoi(); double sum = this->physicalProperties.getRho(); for(int i= 0;i<rhoi.Size();i++) sum += rhoi[i]; if(sum == 0.0) return 0; // Get R * accel from the nodes const Vector &Raccel1 = theNodes[0]->getRV(accel); const Vector &Raccel2 = theNodes[1]->getRV(accel); const Vector &Raccel3 = theNodes[2]->getRV(accel); const Vector &Raccel4 = theNodes[3]->getRV(accel); if(2 != Raccel1.Size() || 2 != Raccel2.Size() || 2 != Raccel3.Size() || 2 != Raccel4.Size()) { std::cerr << "XC::FourNodeQuad::addInertiaLoadToUnbalance matrix and vector sizes are incompatable\n"; return -1; } static double ra[8]; ra[0] = Raccel1(0); ra[1] = Raccel1(1); ra[2] = Raccel2(0); ra[3] = Raccel2(1); ra[4] = Raccel3(0); ra[5] = Raccel3(1); ra[6] = Raccel4(0); ra[7] = Raccel4(1); // Compute mass matrix this->getMass(); // Want to add ( - fact * M R * accel ) to unbalance // Take advantage of lumped mass matrix for(int i= 0; i < 2*numNodes(); i++) load(i)+= -K(i,i)*ra[i]; return 0; }
/* * inserts a node at the root * ignores the case where n->value == value */ TreeNode insertRoot(TreeNode n, int value) { if (n == NULL){ n = newNode(value); } else{ n->nnodes = numNodes(n); // count the nodes } if (value < n->value){ n->leftnode = insertRoot(n->leftnode, value); n = rotateRight(n); } if (value > n->value){ n->rightnode = insertRoot(n->rightnode, value); n = rotateLeft(n); } return n; }
//! @brief Return the mass matrix. const XC::Matrix &XC::FourNodeQuad::getMass(void) const { K.Zero(); static Vector rhoi(4); rhoi= physicalProperties.getRhoi(); double sum = this->physicalProperties.getRho(); for(int i= 0;i<rhoi.Size();i++) sum += rhoi[i]; if(sum != 0.0) { double rhodvol, Nrho; // Compute a lumped mass matrix for(size_t i= 0;i<physicalProperties.size();i++) { // Determine Jacobian for this integration point const GaussPoint &gp= getGaussModel().getGaussPoints()[i]; rhodvol = this->shapeFunction(gp); // Element plus material density ... MAY WANT TO REMOVE ELEMENT DENSITY double tmp = physicalProperties.getRho() + rhoi[i]; rhodvol*= (tmp*physicalProperties.getThickness()*gp.weight()); for(int alpha = 0, ia = 0; alpha<numNodes(); alpha++, ia++) { Nrho = shp[2][alpha]*rhodvol; K(ia,ia) += Nrho; ia++; K(ia,ia) += Nrho; } } } if(isDead()) K*=dead_srf; return K; }
TargetNodeBasePtr Route::get(unsigned int index) const { assert (index < numNodes()); return m_route[index]; }
// This only copies the current information of the argument e to // *this ExprRep. void ExprRep::reduceTo(const ExprRep *e) { if (e->appComputed()) { appValue() = e->appValue(); appComputed() = true; flagsComputed() = true; knownPrecision() = e->knownPrecision(); #ifdef CORE_DEBUG relPrecision() = e->relPrecision(); absPrecision() = e->absPrecision(); numNodes() = e->numNodes(); #endif } d_e() = e->d_e(); //visited() = e->visited(); sign() = e->sign(); uMSB() = e->uMSB(); lMSB() = e->lMSB(); // length() = e->length(); // fixed? original = 1 measure() = e->measure(); // BFMSS[2,5] bound. u25() = e->u25(); l25() = e->l25(); v2p() = e->v2p(); v2m() = e->v2m(); v5p() = e->v5p(); v5m() = e->v5m(); high() = e->high(); low() = e->low(); // fixed? original = 0 lc() = e->lc(); tc() = e->tc(); // Chee (Mar 23, 2004), Notes on ratFlag(): // =============================================================== // For more information on the use of this flag, see progs/pentagon. // This is an integer valued member of the NodeInfo class. // Its value is used to determine whether // we can ``reduce'' an Expression to a single node containing // a BigRat value. This reduction is done if the global variable // rationalReduceFlag=true. The default value is false. // This is the intepretation of ratFlag: // ratFlag < 0 means irrational // ratFlag = 0 means not initialized // ratFlag > 0 means rational // Currently, ratFlag>0 is an upper bound on the size of the expression, // since we recursively compute // ratFlag(v) = ratFlag(v.lchild)+ratFlag(v.rchild) + 1. // PROPOSAL: if ratFlag() > RAT_REDUCE_THRESHHOLD // then we automatically do a reduction. We must determine // an empirical value for RAT_REDUCE_THRESHOLD if (rationalReduceFlag) { ratFlag() = e->ratFlag(); if (e->ratFlag() > 0 && e->ratValue() != NULL) { ratFlag() ++; if (ratValue() == NULL) ratValue() = new BigRat(*(e->ratValue())); else *(ratValue()) = *(e->ratValue()); } else ratFlag() = -1; } }
Visualization::Abstract::DataSet* CitcomtVectorFile::load(const std::vector<std::string>& args,Comm::MulticastPipe* pipe) const { /* Open the data file: */ Misc::File dataFile(args[0].c_str(),"rt"); /* Check if the user wants to load a specific variable: */ bool logScale=false; const char* varStart=0; const char* varEnd=0; int varLen=0; if(args.size()>2&&args[2][0]!='-') { /* Parse the search variable name: */ varStart=args[2].c_str(); if(strncasecmp(varStart,"log(",4)==0) { /* Use a logarithmic scale: */ logScale=true; /* Take the string in parentheses as search variable name: */ varStart+=4; for(varEnd=varStart;*varEnd!='\0'&&*varEnd!=')';++varEnd) ; } else { /* Take the entire string as search variable name: */ for(varEnd=varStart;*varEnd!='\0';++varEnd) ; } varLen=varEnd-varStart; } /********************************************************* Parse any useful information from the CITCOMT file header: *********************************************************/ /* Size of data set in C memory / file order: Z varies fastest, then X, then Y: */ DS::Index numNodes(-1,-1,-1); /* Ordering of coordinate columns in the file: */ int coordColumn[3]={-1,-1,-1}; /* Index of data columns: */ int dataColumn[1]={-1}; char* dataNames[1]={0}; /* Mapping from coordinate columns to spherical coordinates (lat, long, rad): */ int sphericalOrder[3]={-1,-1,-1}; /* Read the first line: */ char line[256]; dataFile.gets(line,sizeof(line)); /* Parse the entire header: */ while(line[0]=='#') { /* Skip hash marks and whitespace: */ char* cPtr=line; while(*cPtr!='\0'&&(*cPtr=='#'||isspace(*cPtr))) ++cPtr; /* Check which header line this is: */ if(strncasecmp(cPtr,"NODES",5)==0) { /* Parse the number of nodes: */ do { /* Check which dimension this is and parse the number of nodes: */ if(toupper(cPtr[5])=='Y') // Y column varies most slowly numNodes[0]=atoi(cPtr+7); else if(toupper(cPtr[5])=='X') numNodes[1]=atoi(cPtr+7); if(toupper(cPtr[5])=='Z') // Z column varies fastest numNodes[2]=atoi(cPtr+7); /* Go to the next field: */ while(*cPtr!='\0'&&!isspace(*cPtr)) ++cPtr; while(*cPtr!='\0'&&isspace(*cPtr)) ++cPtr; } while(strncasecmp(cPtr,"NODES",5)==0); } else if((toupper(cPtr[0])=='X'||toupper(cPtr[0])=='Y'||toupper(cPtr[0])=='Z')&&cPtr[1]=='-') { /* Parse spherical coordinate assignments: */ do { /* Remember which coordinate this is: */ int coordIndex=int(toupper(cPtr[0]))-int('X'); /* Find the end of the spherical component string: */ char* endPtr; for(endPtr=cPtr;*endPtr!='\0'&&*endPtr!=','&&!isspace(*endPtr);++endPtr) ; /* Check which component is assigned: */ if(endPtr-cPtr==5&&strncasecmp(cPtr+2,"LAT",3)==0) sphericalOrder[0]=coordIndex; else if(endPtr-cPtr==5&&strncasecmp(cPtr+2,"LON",3)==0) sphericalOrder[1]=coordIndex; if(endPtr-cPtr==8&&strncasecmp(cPtr+2,"RADIUS",3)==0) sphericalOrder[2]=coordIndex; /* Go to the next field: */ cPtr=endPtr; if(*cPtr==',') ++cPtr; while(*cPtr!='\0'&&isspace(*cPtr)) ++cPtr; } while((toupper(cPtr[0])=='X'||toupper(cPtr[0])=='Y'||toupper(cPtr[0])=='Z')&&cPtr[1]=='-'); } else if(*cPtr=='|') { /* Parse column assignments: */ int columnIndex=0; do { /* Skip separator and whitespace: */ while(*cPtr!='\0'&&(*cPtr=='|'||isspace(*cPtr))) ++cPtr; /* Find the end of the column string: */ char* endPtr; for(endPtr=cPtr;*endPtr!='\0'&&!isspace(*endPtr);++endPtr) ; /* Check which column this is: */ if(endPtr-cPtr==1&&strncasecmp(cPtr,"X",1)==0) coordColumn[0]=columnIndex; else if(endPtr-cPtr==1&&strncasecmp(cPtr,"Y",1)==0) coordColumn[1]=columnIndex; else if(endPtr-cPtr==1&&strncasecmp(cPtr,"Z",1)==0) coordColumn[2]=columnIndex; else if(endPtr-cPtr==4&&strncasecmp(cPtr,"NODE",1)==0) { /* Ignore this column */ } else if(dataColumn[0]<0) { if(varStart==0||(endPtr-cPtr==varLen&&strncasecmp(varStart,cPtr,varLen)==0)) { /* Treat this column as the data column: */ dataColumn[0]=columnIndex; /* Remember the name of the data value: */ if(logScale) { dataNames[0]=new char[varLen+6]; memcpy(dataNames[0],"Log(",4); memcpy(dataNames[0]+4,cPtr,varLen); dataNames[0][4+varLen]=')'; dataNames[0][4+varLen+1]='\0'; } else { dataNames[0]=new char[varLen+1]; memcpy(dataNames[0],cPtr,varLen); dataNames[0][varLen]='\0'; } } } /* Go to the next column: */ cPtr=endPtr; while(*cPtr!='\0'&&isspace(*cPtr)) ++cPtr; ++columnIndex; } while(*cPtr=='|'); } /* Go to the next line: */ dataFile.gets(line,sizeof(line)); } /* Check if all required header information has been read: */ bool headerValid=true; for(int i=0;i<3;++i) if(numNodes[i]<0) headerValid=false; for(int i=0;i<3;++i) if(coordColumn[i]<0) headerValid=false; for(int i=0;i<1;++i) if(dataColumn[i]<0) { if(varStart!=0) Misc::throwStdErr("CitcomtFile::load: Data variable %s not found in CITCOMT header in input file %s",args[2].c_str(),args[0].c_str()); headerValid=false; } if(!headerValid) Misc::throwStdErr("CitcomtFile::load: Invalid CITCOMT header in input file %s",args[0].c_str()); /* Create result data set: */ EarthDataSet<DataSet>* result=new EarthDataSet<DataSet>(args); result->getDs().setData(numNodes); result->setFlatteningFactor(0.0); // Spherical geoid model to simplify vector transformation /* Set the data value's name: */ result->getDataValue().setScalarVariableName(dataNames[0]); result->getDataValue().setVectorVariableName("Velocity"); /* Check if the file is stored in spherical coordinates: */ bool sphericalCoordinates=true; for(int i=0;i<3;++i) if(sphericalOrder[i]<0) sphericalCoordinates=false; /* Constant parameters for geoid formula: */ const double a=6378.14e3; // Equatorial radius in m // const double f=1.0/298.247; // Geoid flattening factor const double scaleFactor=1.0e-3; // Scale factor for Cartesian coordinates /* Determine the number of significant columns: */ int numColumns=0; for(int i=0;i<3;++i) if(numColumns<coordColumn[i]) numColumns=coordColumn[i]; for(int i=0;i<1;++i) if(numColumns<dataColumn[i]) numColumns=dataColumn[i]; ++numColumns; /* Compute a mapping from column indices to coordinate components/data value: */ int* columnMapping=new int[numColumns]; for(int i=0;i<numColumns;++i) columnMapping[i]=-1; for(int i=0;i<3;++i) columnMapping[coordColumn[i]]=i; for(int i=0;i<1;++i) columnMapping[dataColumn[i]]=3+i; /* Read all vertex positions and values: */ Misc::File vectorFile(args[1].c_str(),"rt"); std::cout<<"Reading grid vertex positions and values... 0%"<<std::flush; DS::Array& vertices=result->getDs().getVertices(); DS::Index index; for(index[0]=0;index[0]<vertices.getSize(0);++index[0]) { for(index[1]=0;index[1]<vertices.getSize(1);++index[1]) for(index[2]=0;index[2]<vertices.getSize(2);++index[2]) { /* Parse the coordinate components and the data value from the line: */ double columns[4]; char* cPtr=line; for(int i=0;i<numColumns;++i) { /* Read the column value: */ double val=strtod(cPtr,&cPtr); if(columnMapping[i]>=0) columns[columnMapping[i]]=val; } /* Read the next line from the vector file and parse the vector components: */ vectorFile.gets(line,sizeof(line)); cPtr=line; double vector[3]; /* Order in the file is longitude, radius, latitude: */ vector[1]=strtod(cPtr,&cPtr); vector[2]=strtod(cPtr,&cPtr); vector[0]=strtod(cPtr,&cPtr); DS::GridVertex& v=vertices(index); if(sphericalCoordinates) { /* Convert from spherical to Cartesian coordinates: */ double latitude=columns[sphericalOrder[0]]; double longitude=columns[sphericalOrder[1]]; double radius=columns[sphericalOrder[2]]; double s0=Math::sin(latitude); double c0=Math::cos(latitude); double s1=Math::sin(longitude); double c1=Math::cos(longitude); #if 1 double r=a*radius*scaleFactor; // Use spherical globe model to simplify vector conversion #else double r=(a*(1.0-f*Math::sqr(s0))*radius)*scaleFactor; #endif double xy=r*c0; v.pos[0]=float(xy*c1); v.pos[1]=float(xy*s1); v.pos[2]=float(r*s0); /* Store the scalar value: */ if(logScale) v.value.scalar=float(Math::log10(columns[3])); else v.value.scalar=float(columns[3]); /* Convert the vector value from spherical to Cartesian coordinates: */ v.value.vector[0]=float(c1*(c0*vector[2]-s0*vector[0])-s1*vector[1]); v.value.vector[1]=float(s1*(c0*vector[2]-s0*vector[0])+c1*vector[1]); v.value.vector[2]=float(c0*vector[0]+s0*vector[2]); } else { /* Store the vertex position and value: */ for(int i=0;i<3;++i) v.pos[i]=float(columns[i]); if(logScale) v.value.scalar=float(Math::log10(columns[3])); else v.value.scalar=float(columns[3]); for(int i=0;i<3;++i) v.value.vector[i]=float(vector[i]); } /* Read the next line from the file: */ dataFile.gets(line,sizeof(line)); } std::cout<<"\b\b\b\b"<<std::setw(3)<<((index[0]+1)*100)/vertices.getSize(0)<<"%"<<std::flush; } std::cout<<"\b\b\b\bdone"<<std::endl; /* Clean up: */ delete[] columnMapping; /* Finalize the grid structure: */ result->getDs().finalizeGrid(); #if 0 { /* Save the grid to a pair of binary files: */ Misc::LargeFile gridFile("GridFile.grid","wb",Misc::LargeFile::LittleEndian); Misc::LargeFile dataFile("GridFile.dat","wb",Misc::LargeFile::LittleEndian); /* Write the grid file headers: */ gridFile.write<int>(result->getDs().getNumVertices().getComponents(),3); dataFile.write<int>(result->getDs().getNumVertices().getComponents(),3); dataFile.write<int>(2); dataFile.write<int>(1); dataFile.write<int>(strlen(dataNames[0])); dataFile.write<char>(dataNames[0],strlen(dataNames[0])); dataFile.write<int>(3); dataFile.write<int>(strlen("Velocity")); dataFile.write<char>("Velocity",strlen("Velocity")); /* Write the vertex positions: */ for(DS::Array::iterator vIt=vertices.begin();vIt!=vertices.end();++vIt) { gridFile.write<float>(vIt->pos.getComponents(),3); dataFile.write<Value>(vIt->value); } } #endif /* Clean up and return result: */ delete[] dataNames[0]; return result; }
void Graph::printGraph() { cout << "Number of nodes: " << numNodes() << ", number of edges: " << numEdges() << endl; vector<Edge>::iterator iter; for( iter = edges.begin(); iter != edges.end(); iter++ ) iter->printEdge(); }