Beispiel #1
0
	// return all nodes matching the volume-query
	// description, starting search at the subtree
	// with node-index <nodeNum>
	//
	// NOTE: do not call before balancing the tree
	void GetNodes(NodeVolumeQuery<T>* query, size_t nodeNum, unsigned int depth = 0) {
		if (nodeNum >= nodes.size()) {
			return;
		}

		const T nodeInst = nodes[nodeNum];
		float nodeDist = 0.0f;

		if ((nodeNum << 1) < nodes.size()) {
			// if in the left half of the array, we can examine child nodes
			nodeDist = query->GetPos()[nodeInst->GetAxis()] - nodeInst->GetPos()[nodeInst->GetAxis()];

			if (nodeDist > 0.0f) {
				// search right of the axis-plane first
				GetNodes(query, (nodeNum << 1) + 1, depth + 1);

				if ((nodeDist * nodeDist) < query->GetMaxNodeDist()) {
					GetNodes(query, (nodeNum << 1), depth + 1);
				}
			} else {
				// search left of the axis-plane first
				GetNodes(query, (nodeNum << 1), depth + 1);

				if ((nodeDist * nodeDist) < query->GetMaxNodeDist()) {
					GetNodes(query, (nodeNum << 1) + 1, depth + 1);
				}
			}
		}

		query->AddNode(nodeInst);
	}
Beispiel #2
0
void TBPGraph::GetNIdV(TIntV& NIdV) const {
  NIdV.Gen(GetNodes(), 0);
  for (int N=LeftH.FFirstKeyId(); LeftH.FNextKeyId(N); ) {
    NIdV.Add(LeftH.GetKey(N)); }
  for (int N=RightH.FFirstKeyId(); RightH.FNextKeyId(N); ) {
    NIdV.Add(RightH.GetKey(N)); }
}
Beispiel #3
0
int TBPGraph::GetRndNId(TRnd& Rnd) { 
  const int NNodes = GetNodes();
  if (Rnd.GetUniDevInt(NNodes) < GetLNodes()) {
    return GetRndLNId(Rnd); }
  else {
    return GetRndRNId(Rnd); }
}
Beispiel #4
0
void TWgtNet::DelMinWgtNodes(const double MinWgt) {
  printf("Deleting Min Wgt %g nodes\n", MinWgt);
  printf("  (%d,%d)  -->", GetNodes(), GetEdges());
  TIntV DelNIdV;  
  for (TNodeI NI = BegNI(); NI < EndNI(); NI++) {
    double wgt = 0;
    for (int e = 0; e < NI.GetOutDeg(); e++) { 
      wgt += NI.GetOutEDat(e);
    }
    if (wgt < MinWgt) { DelNIdV.Add(NI.GetId()); }
  }
  for (int d = 0; d < DelNIdV.Len(); d++) {
    DelNode(DelNIdV[d]);
  }
  printf("  (%d,%d)\n", GetNodes(), GetEdges());
}
Beispiel #5
0
int GenPy(PUNGraph &res, ofstream& TFile, const TStr& parameters)
{
	Env = TEnv(parameters, TNotify::StdNotify);
	TStr mN = Env.GetIfArgPrefixStr("-module:", "random_graphs", "Module name");
	TStr fN = Env.GetIfArgPrefixStr("-func:", "fast_gnp_random_graph", "Function name");
	
	PyObject **G = new PyObject*[1];
		
	char *moduleName = mN.CStr();
	char *funcName = fN.CStr();
	AddFuncInfo();
	TStrV args, argTypes;
	if (!ParseArgs(funcName, parameters, args, argTypes))
	{
		printf("Fail to parse arguments for NetworkX generation...\n");
		return 0;
	};
	TExeTm execTime;
	if (!CallPyFunction(moduleName, funcName, args, argTypes, G))
	{
		cout << "CallPyFunction() raised error. Execution terminated.\n";
		system("pause");
		exit(1);
	};
	
	TFile << "Time of generation of graph by NetworkX: " << execTime.GetTmStr() << endl; 

	execTime.Tick();
	PyObject*** nodes = new PyObject**[1];
	GetNodes(G, nodes);
	int nodesCount = PyList_Size(*(nodes[0]));
	//printf("nodesCount = %d, ", nodesCount);
	res = PUNGraph::TObj::New();
    res->Reserve(nodesCount, nodesCount*nodesCount);
	for (size_t i = 0; i < nodesCount; i++)
		res->AddNode(i);
	Py_DECREF(nodes);

	PyObject*** edges = new PyObject**[1];
	GetEdges(G, edges);
	int edgesCount = PyList_Size(*(edges[0]));
	//printf("edgesCount = %d\n", edgesCount);
	for (size_t i = 0; i < edgesCount; i++)
	{
		PyObject* item = PySequence_Fast_GET_ITEM(*(edges[0]), i);
		int v1, v2;
		PyObject* node = PySequence_Fast_GET_ITEM(item,0);
		v1 = PyLong_AsLong(node);
		node = PySequence_Fast_GET_ITEM(item,1);
		v2 = PyLong_AsLong(node);
		res->AddEdge(v1,v2);
	}
	TFile << "Time of copying of graph from NetworkX representation: " << execTime.GetTmStr() << endl; 
	Py_DECREF(G);
	Py_DECREF(edges);
	//Py_Finalize(); // очищение памяти, отданной интерпретатору
	
	return 0;
}
void ElementBase::GetShapeFunctionsForCracks(int *numnds,double *fn,int *nds,Vector *pos) const
{
#ifdef CRACK_POINT
	Vector xipos;
	GetNodes(numnds,nds);
	GetXiPos(pos,&xipos);
	ShapeFunction(&xipos,FALSE,&fn[1],NULL,NULL,NULL);
#else
	Vector xipos,lp;
	int ndIDs[maxShapeNodes];
	
    switch(useGimp)
    {   case POINT_GIMP:
        	// Load element noodes, dimensionless position, and shape functinos
            GetNodes(numnds,nds);
            GetXiPos(pos,&xipos);
            ShapeFunction(&xipos,FALSE,&fn[1],NULL,NULL,NULL);
            break;
            
        case LINEAR_CPDI:
        case QUADRATIC_CPDI:
			// since no material point, CPDI uses GIMP method
        case UNIFORM_GIMP:
            GetXiPos(pos,&xipos);
            lp.x = mpmgrid.GetParticleSemiLength();
            lp.y = lp.x;
            lp.z = lp.x;
            GetGimpNodes(numnds,nds,ndIDs,&xipos,lp);
            GimpShapeFunction(&xipos,*numnds,ndIDs,FALSE,&fn[1],NULL,NULL,NULL,lp);
            GimpCompact(numnds,nds,fn,NULL,NULL,NULL);
            break;
            
		case LINEAR_CPDI_AS:
			// since no material point, CPDI uses GIMP method
        case UNIFORM_GIMP_AS:
            GetXiPos(pos,&xipos);
            lp.x = mpmgrid.GetParticleSemiLength();
            lp.y = lp.x;
            lp.z = lp.x;
            GetGimpNodes(numnds,nds,ndIDs,&xipos,lp);
            GimpShapeFunctionAS(&xipos,*numnds,ndIDs,FALSE,&fn[1],NULL,NULL,NULL,lp);
            GimpCompact(numnds,nds,fn,NULL,NULL,NULL);
            break;
     }
#endif
}
Beispiel #7
0
void Tree<N>::ResetNodeIds()
{
	std::vector<N*> nodes = GetNodes();
	for(unsigned int i = 0; i < nodes.size(); i++)
  {
    nodes[i]->SetId(i);
  }
}
Beispiel #8
0
void TNEANetMP::Dump(FILE *OutF) const {
  const int NodePlaces = (int) ceil(log10((double) GetNodes()));
  const int EdgePlaces = (int) ceil(log10((double) GetEdges()));
  fprintf(OutF, "-------------------------------------------------\nDirected Node-Edge Network: nodes: %d, edges: %d\n", GetNodes(), GetEdges());
  for (TNodeI NodeI = BegNI(); NodeI < EndNI(); NodeI++) {
    fprintf(OutF, "  %*d]\n", NodePlaces, NodeI.GetId());
    // load node attributes
    TIntV IntAttrN;
    IntAttrValueNI(NodeI.GetId(), IntAttrN);
    fprintf(OutF, "    nai[%d]", IntAttrN.Len());
    for (int i = 0; i < IntAttrN.Len(); i++) {
      fprintf(OutF, " %*i", NodePlaces, IntAttrN[i]()); }
    TStrV StrAttrN;
    StrAttrValueNI(NodeI.GetId(), StrAttrN);
    fprintf(OutF, "    nas[%d]", StrAttrN.Len());
    for (int i = 0; i < StrAttrN.Len(); i++) {
      fprintf(OutF, " %*s", NodePlaces, StrAttrN[i]()); }
    TFltV FltAttrN;
    FltAttrValueNI(NodeI.GetId(), FltAttrN);
    fprintf(OutF, "    naf[%d]", FltAttrN.Len());
    for (int i = 0; i < FltAttrN.Len(); i++) {
      fprintf(OutF, " %*f", NodePlaces, FltAttrN[i]()); }

    fprintf(OutF, "    in[%d]", NodeI.GetInDeg());
    for (int edge = 0; edge < NodeI.GetInDeg(); edge++) {
      fprintf(OutF, " %*d", EdgePlaces, NodeI.GetInEId(edge)); }
    fprintf(OutF, "\n");
    fprintf(OutF, "    out[%d]", NodeI.GetOutDeg());
    for (int edge = 0; edge < NodeI.GetOutDeg(); edge++) {
      fprintf(OutF, " %*d", EdgePlaces, NodeI.GetOutEId(edge)); }
    fprintf(OutF, "\n");
  }
  for (TEdgeI EdgeI = BegEI(); EdgeI < EndEI(); EdgeI++) {
    fprintf(OutF, "  %*d]  %*d  ->  %*d", EdgePlaces, EdgeI.GetId(), NodePlaces, EdgeI.GetSrcNId(), NodePlaces, EdgeI.GetDstNId());

    // load edge attributes
    TIntV IntAttrE;
    IntAttrValueEI(EdgeI.GetId(), IntAttrE);
    fprintf(OutF, "    eai[%d]", IntAttrE.Len());
    for (int i = 0; i < IntAttrE.Len(); i++) {
      fprintf(OutF, " %*i", EdgePlaces, IntAttrE[i]());
    }
    TStrV StrAttrE;
    StrAttrValueEI(EdgeI.GetId(), StrAttrE);
    fprintf(OutF, "    eas[%d]", StrAttrE.Len());
    for (int i = 0; i < StrAttrE.Len(); i++) {
      fprintf(OutF, " %*s", EdgePlaces, StrAttrE[i]());
    }
    TFltV FltAttrE;
    FltAttrValueEI(EdgeI.GetId(), FltAttrE);
    fprintf(OutF, "    eaf[%d]", FltAttrE.Len());
    for (int i = 0; i < FltAttrE.Len(); i++) {
      fprintf(OutF, " %*f", EdgePlaces, FltAttrE[i]());
    }
    fprintf(OutF, "\n");
  }
  fprintf(OutF, "\n");
}
Beispiel #9
0
PNGraph TGraphKey::GetNGraph() const {
  PNGraph G = TNGraph::New();
  for (int i = 0; i < GetNodes(); i++) G->AddNode(i);
  for (int e = 0; e < GetEdges(); e++) {
    G->AddEdge(EdgeV[e].Val1, EdgeV[e].Val2);
  }
  G->Defrag();
  return G;
}
/* Just get nodes and shape functions
	Load number of nodes into numnds
	Load node numbers into nds[1]...
	Load shape functions into fn[1]...
	See other GetShapeFunctions() if need to change
 NOTE: This is called at various places in the time step when shape functions are needed. It should
	recalculate the ones found at the begnning of the time step using precalculated xipos
    or CPDI info, which are found in initialization
 throws CommonException() if too many CPDI nodes
*/
void ElementBase::GetShapeFunctions(int *numnds,double *fn,int *nds,MPMBase *mpmptr) const
{
    Vector lp;
    
    switch(useGimp)
    {   case POINT_GIMP:
        	// load coordinates if not already done
            GetNodes(numnds,nds);
            ShapeFunction(mpmptr->GetNcpos(),FALSE,&fn[1],NULL,NULL,NULL);
            break;
            
        case UNIFORM_GIMP:
        {	// GIMP analysis
            int ndIDs[maxShapeNodes];
            Vector *xipos = mpmptr->GetNcpos();
            mpmptr->GetDimensionlessSize(lp);
            GetGimpNodes(numnds,nds,ndIDs,xipos,lp);
            GimpShapeFunction(xipos,*numnds,ndIDs,FALSE,&fn[1],NULL,NULL,NULL,lp);
            GimpCompact(numnds,nds,fn,NULL,NULL,NULL);
            break;
        }
            
        case UNIFORM_GIMP_AS:
        {	// GIMP analysis
            int ndIDs[maxShapeNodes];
            Vector *xipos = mpmptr->GetNcpos();
            mpmptr->GetDimensionlessSize(lp);
            GetGimpNodes(numnds,nds,ndIDs,xipos,lp);
            GimpShapeFunctionAS(xipos,*numnds,ndIDs,FALSE,&fn[1],NULL,NULL,NULL,lp);
            GimpCompact(numnds,nds,fn,NULL,NULL,NULL);
            break;
        }
            
        case LINEAR_CPDI:
		case LINEAR_CPDI_AS:
        case QUADRATIC_CPDI:
        {   if(theMaterials[mpmptr->MatID()]->Rigid())
            {	// GIMP analysis
                int ndIDs[maxShapeNodes];
                Vector *xipos = mpmptr->GetNcpos();
                mpmptr->GetDimensionlessSize(lp);
                GetGimpNodes(numnds,nds,ndIDs,xipos,lp);
                if(fmobj->IsAxisymmetric())
                    GimpShapeFunctionAS(xipos,*numnds,ndIDs,FALSE,&fn[1],NULL,NULL,NULL,lp);
                else
                    GimpShapeFunction(xipos,*numnds,ndIDs,FALSE,&fn[1],NULL,NULL,NULL,lp);
                GimpCompact(numnds,nds,fn,NULL,NULL,NULL);
            }
            else
            {   *numnds = GetCPDIFunctions(nds,fn,NULL,NULL,NULL,mpmptr);
            }
            break;
		}
    }
}
bool ribi::cmap::HasCenterNode(const ConceptMap& c) noexcept
{
  const auto nodes = GetNodes(c);
  const auto i = std::find_if(
    std::begin(nodes),std::end(nodes),
    [](const Node& node) {
      return IsCenterNode(node);
    }
  );
  return i != std::end(nodes);
}
Beispiel #12
0
void TUNGraph::Dump(FILE *OutF) const {
  const int NodePlaces = (int) ceil(log10((double) GetNodes()));
  fprintf(OutF, "-------------------------------------------------\nUndirected Node Graph: nodes: %d, edges: %d\n", GetNodes(), GetEdges());
  for (int N = NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
    const TNode& Node = NodeH[N];
    fprintf(OutF, "  %*d [%d] ", NodePlaces, Node.GetId(), Node.GetDeg());
    for (int edge = 0; edge < Node.GetDeg(); edge++) {
      fprintf(OutF, " %*d", NodePlaces, Node.GetNbhNId(edge)); }
    fprintf(OutF, "\n");
  }
  fprintf(OutF, "\n");
}
void ribi::braw::QtPrintRatingDialog::showEvent(QShowEvent *)
{
    //Concept map
    {
        m_widget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
        m_widget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
        m_widget->setMaximumHeight(m_widget->scene()->itemsBoundingRect().height() + 2);
        m_widget->setMinimumHeight(m_widget->scene()->itemsBoundingRect().height() + 2);
        //Fit concept map to widget
        m_widget->fitInView(m_widget->scene()->itemsBoundingRect());
    }
    //Concept map as text
    {
        assert(ui->widget_concept_map_as_text->layout());
        //std::string text;
        const int n_nodes = static_cast<int>(GetNodes(m_file.GetConceptMap()).size());
        for (int node_index = 1; node_index != n_nodes; ++node_index) //1: skip center node
        {
            const auto node = GetNodes(m_file.GetConceptMap()).at(node_index);
            cmap::QtConceptMapRatedConceptDialog * const widget
                = new cmap::QtConceptMapRatedConceptDialog(m_file.GetConceptMap(),node);
            assert(widget);
            ui->widget_concept_map_as_text->layout()->addWidget(widget);
        }
    }

    //Copied from caller
    QtDisplay().DisplayRatedConcepts(m_file,this->GetTableConcepts());
    {
        const int sz = static_cast<int>(GetNodes(m_file.GetConceptMap()).size());
        //Standard row is 30 pixels high, header 25 pixels
        this->GetTableConcepts()->setMinimumHeight( ((sz-1) * 30) + 26 );
    }

    QtDisplay().DisplayExamples(m_file,this->GetTableExamples());
    QtDisplay().DisplayValues(m_file,this->GetTableValues());
    QtDisplay().DisplayMiscValues(m_file,this->GetTableMiscValues());
}
void ElementVisitor::Visit_HardwareUnit( const ESMoL::HardwareUnit & hwunit )
{
	// Basic idea:  Collect all IChans and OChans and make sure they each have unique ChanNum values

	set< ESMoL::Node > collect_nodes;
	GetNodes( hwunit, collect_nodes );  // collect all nodes within this hardware design

	// Collect the IChans, OChans, and channel numbers for each
	set< ESMoL::IChan > collect_ichans;
	set< ESMoL::OChan > collect_ochans;
	long long max_ichan_num = 0, max_ochan_num = 0;
	for ( set< ESMoL::Node >::iterator nodeIter = collect_nodes.begin(); nodeIter != collect_nodes.end(); nodeIter++ )
	{
		set< ESMoL::IChan > ichans = (*nodeIter).IChan_kind_children();
		for ( set< ESMoL::IChan >::iterator ichanIter = ichans.begin(); ichanIter != ichans.end(); ichanIter++ )
		{
			collect_ichans.insert( *ichanIter );
			if ( (*ichanIter).ChanNum() > max_ichan_num )
				max_ichan_num = (*ichanIter).ChanNum();
		}
		
		set< ESMoL::OChan > ochans = (*nodeIter).OChan_kind_children();
		for ( set< ESMoL::OChan >::iterator ochanIter = ochans.begin(); ochanIter != ochans.end(); ochanIter++ )
		{
			collect_ochans.insert( *ochanIter );
			if ( (*ochanIter).ChanNum() > max_ochan_num )
				max_ochan_num = (*ochanIter).ChanNum();
		}
	}

	// Go through each set of channel objects and assign unassigned channels
	long long index = max_ichan_num + 1;
	for ( set< ESMoL::IChan >::iterator ichanIter = collect_ichans.begin(); ichanIter != collect_ichans.end(); ichanIter++ )
	{
		if ( (*ichanIter).ChanNum() == -1 )
		{
			(*ichanIter).ChanNum() = index++;
		}
	}

	index = max_ochan_num + 1;
	for ( set< ESMoL::OChan >::iterator ochanIter = collect_ochans.begin(); ochanIter != collect_ochans.end(); ochanIter++ )
	{
		if ( (*ochanIter).ChanNum() == -1 )
		{
			(*ochanIter).ChanNum() = index++;
		}
	}
}
Beispiel #15
0
void TNEGraph::Dump(FILE *OutF) const {
  const int NodePlaces = (int) ceil(log10((double) GetNodes()));
  const int EdgePlaces = (int) ceil(log10((double) GetEdges()));
  fprintf(OutF, "-------------------------------------------------\nDirected Node-Edge Graph: nodes: %d, edges: %d\n", GetNodes(), GetEdges());
  for (TNodeI NodeI = BegNI(); NodeI < EndNI(); NodeI++) {
    fprintf(OutF, "  %*d]\n", NodePlaces, NodeI.GetId());
    fprintf(OutF, "    in[%d]", NodeI.GetInDeg());
    for (int edge = 0; edge < NodeI.GetInDeg(); edge++) {
      fprintf(OutF, " %*d", EdgePlaces, NodeI.GetInEId(edge)); }
    fprintf(OutF, "\n    out[%d]", NodeI.GetOutDeg());
    for (int edge = 0; edge < NodeI.GetOutDeg(); edge++) {
      fprintf(OutF, " %*d", EdgePlaces, NodeI.GetOutEId(edge)); }
    fprintf(OutF, "\n");
  }
  for (TEdgeI EdgeI = BegEI(); EdgeI < EndEI(); EdgeI++) {
    fprintf(OutF, "  %*d]  %*d  ->  %*d\n", EdgePlaces, EdgeI.GetId(), NodePlaces, EdgeI.GetSrcNId(), NodePlaces, EdgeI.GetDstNId());
  }
  fprintf(OutF, "\n");
}
Beispiel #16
0
void TBPGraph::Dump(FILE *OutF) const {
  const int NodePlaces = (int) ceil(log10((double) GetNodes()));
  fprintf(OutF, "-------------------------------------------------\nBipartite Graph: nodes: %d+%d=%d, edges: %d\n", GetLNodes(), GetRNodes(), GetNodes(), GetEdges());
  for (int N = LeftH.FFirstKeyId(); LeftH.FNextKeyId(N); ) {
    const TNode& Node = LeftH[N];
    fprintf(OutF, "  %*d [%d] ", NodePlaces, Node.GetId(), Node.GetDeg());
    for (int edge = 0; edge < Node.GetDeg(); edge++) {
      fprintf(OutF, " %*d", NodePlaces, Node.GetNbrNId(edge)); }
    fprintf(OutF, "\n");
  }
  fprintf(OutF, "\n");
  /*// Also dump the 'right' side
  fprintf(OutF, "\n");
  for (int N = RightH.FFirstKeyId(); RightH.FNextKeyId(N); ) {
    const TNode& Node = RightH[N];
    fprintf(OutF, "  %*d [%d] ", NodePlaces, Node.GetId(), Node.GetDeg());
    for (int edge = 0; edge < Node.GetDeg(); edge++) {
      fprintf(OutF, " %*d", NodePlaces, Node.GetNbrNId(edge)); }
    fprintf(OutF, "\n");
  }
  fprintf(OutF, "\n"); //*/
}
Beispiel #17
0
void TGraphKey::SaveGViz(const TStr& OutFNm, const TStr& Desc, const TStr& NodeAttrs, const int& Size) const {
  FILE *F = fopen(OutFNm.CStr(), "wt");
  fprintf(F, "/*****\n");
  fprintf(F, "  Graph (%d, %d)\n", GetNodes(), GetEdges());
  //if (! Desc.Empty()) fprintf(F, "  %s\n", Desc.CStr());
  fprintf(F, "*****/\n\n");
  fprintf(F, "digraph G {\n");
  if (Size != -1) fprintf(F, "  size=\"%d,%d\";\n", Size, Size);
  fprintf(F, "  graph [splines=true overlap=false]\n"); //size=\"12,10\" ratio=fill
  if (NodeAttrs.Empty()) fprintf(F, "  node  [shape=ellipse, width=0.3, height=0.3]\n");
  else fprintf(F, "  node  [shape=ellipse, %s]\n", NodeAttrs.CStr());
  if (! EdgeV.Empty()) {
    for (int e = 0; e < EdgeV.Len(); e++) {
      fprintf(F, "  %d -> %d;\n", EdgeV[e].Val1(), EdgeV[e].Val2()); }
  } else {
    for (int n = 0; n < Nodes; n++) { fprintf(F, "  %d;\n", n); }
  }
  if (! Desc.Empty()) {
    fprintf(F, "  label = \"\\n%s\\n\";", Desc.CStr());
    fprintf(F, "  fontsize=24;\n");
  }
  fprintf(F, "}\n");
  fclose(F);
}
void TreeCommon::GetNodes(float left, float right, float bottom, float top, float glyph_radius,
    vector<CNode*>& pre_level_nodes, vector<CNode*>& current_level_nodes) {

    if (this->type() == VIEW_DEPENDENT_TREE || this->type() == CLUSTER_PROJECTION_TREE) {
        this->ConstructTree(left, right, bottom, top, glyph_radius);
    }

    // Get nodes according to the average distance among all child nodes!!!
    pre_level_nodes.clear();
    current_level_nodes.clear();

    float expected_radius = glyph_radius * 2;
    float view_center_x = (left + right) / 2;
    float view_center_y = (top + bottom) / 2;
    float view_width = right - left;
    float view_height = top - bottom;

    if (this->type() == HIERARCHICAL_TREE) {
        pre_level_nodes.push_back(root_);
    } else if (this->type() == NCUTS_TREE) {
        int temp_level = 0;
        vector<CNode*> level_nodes;
        do {
            temp_level++;
            GetNodes(temp_level, level_nodes);
        } while (level_nodes.size() < 8);
        GetNodes(temp_level - 1, pre_level_nodes);
    } else {
        queue<CNode*> node_queue;
        node_queue.push(root_);
        while (!node_queue.empty()) {
        CNode* node = node_queue.front();
        node->is_visible = false;
        node_queue.pop();
        if (node->type() != CNode::BRANCH) continue;

        float center_x = node->center_pos[0] * point_dataset_->max_pos_range + point_dataset_->original_pos_ranges[0][0];
        float center_y = node->center_pos[1] * point_dataset_->max_pos_range + point_dataset_->original_pos_ranges[1][0];
        float node_width = (node->right - node->left) * point_dataset_->max_pos_range;
        float node_height = (node->top - node->bottom) * point_dataset_->max_pos_range;


        if (abs(view_center_x - center_x)  < (node_width / 2 + view_width / 2)
            && abs(view_center_y - center_y) < (node_height / 2 + view_height / 2)) {
            node->is_expanded = true;
            if (node->average_dis < expected_radius * 4) {
                pre_level_nodes.push_back(node);
            } else {
                CBranch* branch = (CBranch*)node;
                for (int i = 0; i < branch->linked_nodes.size(); ++i)
                    node_queue.push(branch->linked_nodes[i]);
            }
        }
    }
    }

    for (int i = 0; i < pre_level_nodes.size(); ++i) {
        CBranch* branch = (CBranch*)pre_level_nodes[i];
        bool is_children_leaf = false;
        for (int j = 0; j < branch->linked_nodes.size(); ++j)
            if (branch->linked_nodes[j]->type() == CNode::LEAF) {
                is_children_leaf = true;
                break;
            }
        if (!is_children_leaf) {
            for (int j = 0; j < branch->linked_nodes.size(); ++j) {
                CNode* node = branch->linked_nodes[j];

                float center_x = node->center_pos[0] * point_dataset_->max_pos_range + point_dataset_->original_pos_ranges[0][0];
                float center_y = node->center_pos[1] * point_dataset_->max_pos_range + point_dataset_->original_pos_ranges[1][0];
                float node_width = (node->right - node->left) * point_dataset_->max_pos_range;
                float node_height = (node->top - node->bottom) * point_dataset_->max_pos_range;

                if (abs(view_center_x - center_x)  < (node_width / 2 + view_width / 2)
                    && abs(view_center_y - center_y) < (node_height / 2 + view_height / 2))
                    current_level_nodes.push_back(branch->linked_nodes[j]);
            }
        } else {
            current_level_nodes.push_back(branch);
        }
    }
    for (int i = 0; i < current_level_nodes.size(); ++i) {
        current_level_nodes[i]->is_expanded = false;
        current_level_nodes[i]->is_visible = true;
    }
}
Beispiel #19
0
	bool CXmlNode::GetNodes(const CString& sName, CXmlNodes& oNodes)
	{
		oNodes = GetNodes(sName);
		return (0 != oNodes.GetCount());
	}
bool SyntaxTree::HasNode( int startPos, int endPos ) const
{
  return GetNodes( startPos, endPos).size() > 0;
}
Beispiel #21
0
void TUNGraph::GetNIdV(TIntV& NIdV) const {
  NIdV.Gen(GetNodes(), 0);
  for (int N=NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
    NIdV.Add(NodeH.GetKey(N)); }
}
std::vector<ribi::cmap::Node> ribi::cmap::GetSortedNodes(const ConceptMap& c) noexcept
{
  auto v = GetNodes(c);
  std::sort(std::begin(v),std::end(v));
  return v;
}
Beispiel #23
0
void TGStat::Plot(const TGStatDistr& Distr, const TStr& FNmPref, TStr Desc, bool PowerFit) const {
  if (Desc.Empty()) Desc = FNmPref.GetUc();
  if (! HasDistr(Distr) || Distr==gsdUndef || Distr==gsdMx) { return; }
  TPlotInfo Info = GetPlotInfo(Distr);
  TGnuPlot GnuPlot(Info.Val1+TStr(".")+FNmPref, TStr::Fmt("%s. G(%d, %d)", Desc.CStr(), GetNodes(),GetEdges()));
  GnuPlot.SetXYLabel(Info.Val2, Info.Val3);
  GnuPlot.SetScale(Info.Val4);
  const int plotId = GnuPlot.AddPlot(GetDistr(Distr), gpwLinesPoints, "");
  if (PowerFit) { GnuPlot.AddPwrFit(plotId, gpwLines); }
  #ifdef GLib_MACOSX
  GnuPlot.SaveEps();
  #else
  GnuPlot.SavePng();
  #endif
}
Beispiel #24
0
void TGraphKey::SaveTxt(FILE *F) const {
  fprintf(F, "nodes: %d.  edges: %d\n", GetNodes(), GetEdges());
  for (int i = 0; i < EdgeV.Len(); i++) {
    fprintf(F,"  %d\t%d\n", EdgeV[i].Val1(), EdgeV[i].Val2());
  }
}
// by non-element methods that need access to grid shape functions only, and those methods are protected
void ElementBase::GridShapeFunctions(int *numnds,int *nds,Vector *xipos,double *fn) const
{
    GetNodes(numnds,nds);
    ShapeFunction(xipos,FALSE,&fn[1],NULL,NULL,NULL);
}
/* Do several element things at once
    Load number of nodes into numnds
    Load node numbers into nds[1]...
    Load shape functions into fn[1]...
    Load shape function derviatives into xDeriv[1]..., yDeriv[1]..., zDeriv[1]...
        For axisymmetric load zDeriv with shape function / particle radial position
        Input zDeriv must not be NULL
    Input: pointer to material point dimensionless position
   NOTE: This is called at various places in the time step when gradients are needed. It should
    recalculate the ones found at the beginning of the time step using the precalculated xipos
    or CPDI info, which are found in the initialization task
   throws CommonException() if too many CPDI nodes
*/
void ElementBase::GetShapeGradients(int *numnds,double *fn,int *nds,
                                    double *xDeriv,double *yDeriv,double *zDeriv,MPMBase *mpmptr) const
{
    Vector lp;
    
    switch(useGimp)
    {   case POINT_GIMP:
        	// load nodal numbers
            GetNodes(numnds,nds);
            
            // special case for regular mesh
            if(mpmgrid.GetCartesian()>0)
                ShapeFunction(mpmptr->GetNcpos(),TRUE,&fn[1],&xDeriv[1],&yDeriv[1],&zDeriv[1]);
            else
            {	// Load element coordinates
                Vector ce[MaxElNd];
                double fnh[MaxElNd];
                GetCoordinates(ce,*numnds,nds);
                
                // find shape functions and derviatives
                ShapeFunction(mpmptr->GetNcpos(),BMATRIX,&fn[1],&xDeriv[1],&yDeriv[1],&ce[1],NULL,NULL,&fnh[1]);
            }
            break;
            
        case UNIFORM_GIMP:
        {	// uGIMP analysis
            int ndIDs[maxShapeNodes];
            Vector *xipos = mpmptr->GetNcpos();
            mpmptr->GetDimensionlessSize(lp);
            GetGimpNodes(numnds,nds,ndIDs,xipos,lp);
            GimpShapeFunction(xipos,*numnds,ndIDs,TRUE,&fn[1],&xDeriv[1],&yDeriv[1],&zDeriv[1],lp);
            GimpCompact(numnds,nds,fn,xDeriv,yDeriv,zDeriv);
            break;
        }
            
        case UNIFORM_GIMP_AS:
        {	// uGIMP analysis
            int ndIDs[maxShapeNodes];
            Vector *xipos = mpmptr->GetNcpos();
            mpmptr->GetDimensionlessSize(lp);
            GetGimpNodes(numnds,nds,ndIDs,xipos,lp);
            GimpShapeFunctionAS(xipos,*numnds,ndIDs,TRUE,&fn[1],&xDeriv[1],&yDeriv[1],&zDeriv[1],lp);
            GimpCompact(numnds,nds,fn,xDeriv,yDeriv,zDeriv);
            break;
        }
            
        case LINEAR_CPDI:
		case LINEAR_CPDI_AS:
		case QUADRATIC_CPDI:
        {   if(theMaterials[mpmptr->MatID()]->Rigid())
			{	int ndIDs[maxShapeNodes];
                Vector *xipos = mpmptr->GetNcpos();
                mpmptr->GetDimensionlessSize(lp);
                GetGimpNodes(numnds,nds,ndIDs,xipos,lp);
                if(fmobj->IsAxisymmetric())
                    GimpShapeFunctionAS(xipos,*numnds,ndIDs,TRUE,&fn[1],&xDeriv[1],&yDeriv[1],&zDeriv[1],lp);
                else
					GimpShapeFunction(xipos,*numnds,ndIDs,TRUE,&fn[1],&xDeriv[1],&yDeriv[1],&zDeriv[1],lp);
				GimpCompact(numnds,nds,fn,xDeriv,yDeriv,zDeriv);
            }
            else
            {   *numnds = GetCPDIFunctions(nds,fn,xDeriv,yDeriv,zDeriv,mpmptr);
            }
            break;
		}
    }
}
int ribi::cmap::CountCenterNodes(const ConceptMap& c) noexcept
{
  return CountCenterNodes(GetNodes(c));
}
void TMultimodalGraphImplB::GetNIdV(TIntV& NIdV) const {
  NIdV.Gen(GetNodes(), 0);
  for (int N=NodeToModeMapping.FFirstKeyId(); NodeToModeMapping.FNextKeyId(N); ) {
    NIdV.Add(NodeToModeMapping.GetKey(N));
  }
}