Exemple #1
0
static void clearNodes(Node *node) {
  int n;
  for (n = 0; n < node->count; n++)
    clearNodes(node->children[n]);
  free(node->children);
  free(node);
}
void GraphGraphicsView::drawSpecifiedGraph(QList<QList<int> > adjM)
{
    if(&adjM != &adjMatrix)
    {
        clearNodes();
        clearArrows();
        adjMatrix.clear();
        adj.clear();
        adjMatrix = adjM;

        for (int i = 0; i < adjMatrix.length(); ++i) {
            adj.push_back(AdjacencyList());
            for (int j = 0; j < adjMatrix.length(); ++j) {
                if (adjMatrix[i][j] > 0) {
                    adj[i].Insert(j, adjMatrix[i][j]);
                }
            }
        }
    }

    for (int i = 0; i < adjMatrix.size(); ++i) {
        nodes.push_back(new NodeGraphicsItem(QString::number(i+1)));
        scene.addItem(nodes[i]);
        nodes[i]->setPos(qrand() % 500, qrand() % 500);
    }
    reposition();
}
void GraphGraphicsView::drawSpecifiedGraph(int vertices, int edges)
{
    clearNodes();
    clearArrows();
    adjMatrix.clear();
    adj.clear();

    for (int i = 0; i < vertices; ++i) {
        nodes.push_back(new NodeGraphicsItem(QString::number(i+1)));
        scene.addItem(nodes[i]);
        nodes[i]->setPos(qrand() % 500, qrand() % 500);
    }

    for (int i = 0; i < nodes.length(); ++i) {
        adjMatrix.push_back(QList<int>());
        adj.push_back(AdjacencyList());
        for (int j = 0; j < nodes.length(); ++j) {
            if (edges > 0 && i != j)
            {
                int val = qrand() % 11;
                adjMatrix[i].push_back(val);
                if (val > 0) {
                    adj[i].Insert(j,val);
                }
                edges--;
            }
        }
        //adj[i].printValues();
    }

    reposition();
}
Exemple #4
0
Mesh::~Mesh()
{
    Domain* domain = OPS_GetDomain();
    if (domain == 0) return;

    clearEles();
    clearNodes();
}
Exemple #5
0
CMathExpression::CMathExpression(const CExpression & src,
                                 CMathContainer & container,
                                 const bool & replaceDiscontinuousNodes):
  CEvaluationTree(src.getObjectName(), &container, CEvaluationTree::MathExpression),
  mPrerequisites()
{
  clearNodes();

  // Create a converted copy of the existing expression tree.
  mpRootNode = container.copyBranch(src.getRoot(), replaceDiscontinuousNodes);

  compile();
}
void GraphGraphicsView::randomGraph()
{
    clearNodes();
    clearArrows();

    adjMatrix.clear();
    adj.clear();


    int sizeOf = qrand() % 8;

    for (int i = 0; i < sizeOf; ++i) {
        adjMatrix.push_back(QList<int>());
        adj.push_back(AdjacencyList());
        for (int j = 0; j < sizeOf; ++j) {
            if (i != j)
            {
                int val = qrand() % 50;
                if ((val % 10) == 0)
                    val = 0;
                adjMatrix[i].push_back(val);
                if (val > 0) {
                    adj[i].Insert(j,val);

                }
            }
        }
        nodes.push_back(new NodeGraphicsItem(QString::number(i+1)));
        scene.addItem(nodes[i]);
        //qDebug() << i+1 << ": " << adj[i].printValues();
        //adj[i].printValues();
        nodes[i]->setPos(qrand() % 500, qrand() % 500);
    }

    reposition();
    //runPrim();
}
Exemple #7
0
void clearTree(Tree *tree) {
  clearNodes(tree->root);
  free(tree);
}
Exemple #8
0
IfShape::~IfShape()
{
    clearNodes();
}
void GraphGraphicsView::clear()
{
    clearNodes();
    clearArrows();
    clearWeights();
}
void OutlineVectorizer::makeDataRaster(const TRasterP &src)
{
	m_vimage = new TVectorImage();
	if (!src)
		return;
	m_src = src;

	clearNodes();
	clearJunctions();

	int x, y, ii = 0;
	TRaster32P srcRGBM = (TRaster32P)m_src;
	TRasterCM32P srcCM = (TRasterCM32P)m_src;
	TRasterGR8P srcGR = (TRasterGR8P)m_src;

	// Inizializzo DataRasterP per i casi in cui si ha un TRaster32P, un TRasterGR8P o un TRasterCM32P molto grande
	DataRasterP dataRaster(m_src->getSize().lx + 2, m_src->getSize().ly + 2);
	if (srcRGBM || srcGR || (srcCM && srcCM->getLx() * srcCM->getLy() > 5000000)) {
		int ly = dataRaster->getLy();
		int lx = dataRaster->getLx();
		int wrap = dataRaster->getWrap();
		DataPixel *dataPix0 = dataRaster->pixels(0);
		DataPixel *dataPix1 = dataRaster->pixels(0) + m_src->getLx() + 1;
		for (y = 0; y < ly; y++, dataPix0 += wrap, dataPix1 += wrap) {
			dataPix0->m_pos.x = 0;
			dataPix1->m_pos.x = lx - 1;
			dataPix0->m_pos.y = dataPix1->m_pos.y = y;
			dataPix0->m_value = dataPix1->m_value = 0;
			dataPix0->m_ink = dataPix1->m_ink = false;
			dataPix0->m_node = dataPix1->m_node = 0;
		}
		dataPix0 = dataRaster->pixels(0);
		dataPix1 = dataRaster->pixels(ly - 1);
		for (x = 0; x < lx; x++, dataPix0++, dataPix1++) {
			dataPix0->m_pos.x = dataPix1->m_pos.x = x;
			dataPix0->m_pos.y = 0;
			dataPix1->m_pos.y = ly - 1;
			dataPix0->m_value = dataPix1->m_value = 0;
			dataPix0->m_ink = dataPix1->m_ink = false;
			dataPix0->m_node = dataPix1->m_node = 0;
		}
	}

	if (srcRGBM) {
		assert(m_palette);
		int inkId = m_palette->getClosestStyle(m_configuration.m_inkColor);
		if (!inkId || m_configuration.m_inkColor != m_palette->getStyle(inkId)->getMainColor()) {
			inkId = m_palette->getStyleCount();
			m_palette->getStylePage(1)->insertStyle(1, m_configuration.m_inkColor);
			m_palette->setStyle(inkId, m_configuration.m_inkColor);
		}
		assert(inkId);

		m_dataRasterArray.push_back(std::pair<int, DataRasterP>(inkId, dataRaster));
		int maxDistance2 = m_configuration.m_threshold * m_configuration.m_threshold;

		for (y = 0; y < m_src->getLy(); y++) {
			TPixel32 *inPix = srcRGBM->pixels(y);
			TPixel32 *inEndPix = inPix + srcRGBM->getLx();
			DataPixel *dataPix = dataRaster->pixels(y + 1) + 1;
			x = 0;
			while (inPix < inEndPix) {
				*dataPix = DataPixel();
				int distance2 = colorDistance2(m_configuration.m_inkColor, *inPix);

				if (y == 0 || y == m_src->getLy() - 1 || x == 0 || x == m_src->getLx() - 1 || inPix->m == 0) {
					dataPix->m_value = 255;
					dataPix->m_ink = false;
				} else {
					dataPix->m_value = (inPix->r + 2 * inPix->g + inPix->b) >> 2;
					dataPix->m_ink = (distance2 < maxDistance2);
				}
				dataPix->m_pos.x = x++;
				dataPix->m_pos.y = y;
				dataPix->m_node = 0;
				inPix++;
				dataPix++;
			}
		}
	} else if (srcGR) {
OutlineVectorizer::~OutlineVectorizer()
{
	m_protoOutlines.clear();
	clearNodes();
	clearJunctions();
}
Exemple #12
0
ATOM_OctreeNodeChunk::~ATOM_OctreeNodeChunk (void) 
{
  clearNodes ();
}
void WPDefManager::unload( void )
{
	// Clear all nodes inside our local tree
	clearNodes( Items );
	clearNodes( Scripts );
	clearNodes( NPCs );
	clearNodes( StringLists );
	clearNodes( Menus );
	clearNodes( Spells );
	clearNodes( PrivLevels );
	clearNodes( SpawnRegions );
	clearNodes( Regions );
	clearNodes( Multis );
	clearNodes( Texts );
}
Exemple #14
0
CMathExpression::CMathExpression(const CFunction & src,
                                 const CCallParameters< C_FLOAT64 > & callParameters,
                                 CMathContainer & container,
                                 const bool & replaceDiscontinuousNodes):
  CEvaluationTree(src.getObjectName(), &container, CEvaluationTree::MathExpression),
  mPrerequisites()
{
  clearNodes();

  // Deal with the different function types
  switch (src.getType())
    {
      case CEvaluationTree::Function:
      case CEvaluationTree::PreDefined:
      case CEvaluationTree::UserDefined:
      {
        // Create a vector of CEvaluationNodeObject for each variable
        CMath::Variables< CEvaluationNode * > Variables;

        CCallParameters< C_FLOAT64 >::const_iterator it = callParameters.begin();
        CCallParameters< C_FLOAT64 >::const_iterator end = callParameters.end();

        for (; it != end; ++it)
          {
            Variables.push_back(createNodeFromValue(it->value));
          }

        // Create a converted copy of the existing expression tree.
        mpRootNode = container.copyBranch(src.getRoot(), Variables, replaceDiscontinuousNodes);

        // Deleted the created variables
        CMath::Variables< CEvaluationNode * >::iterator itVar = Variables.begin();
        CMath::Variables< CEvaluationNode * >::iterator endVar = Variables.end();

        for (; itVar != endVar; ++itVar)
          {
            pdelete(*itVar);
          }
      }

      break;

      case CEvaluationTree::MassAction:
      {
        // We build a mass action expression based on the call parameters.
        CCallParameters< C_FLOAT64 >::const_iterator it = callParameters.begin();

        // Handle the case we were have an invalid number of call parameters.
        if (callParameters.size() < 2)
          {
            mpRootNode = NULL;
          }
        else
          {
            // We always have reactants
            const C_FLOAT64 * pK = it->value;
            ++it;
            const CCallParameters< C_FLOAT64 > * pSpecies = it->vector;
            ++it;

            CEvaluationNode * pPart = createMassActionPart(pK, pSpecies);

            if (callParameters.size() < 4)
              {
                mpRootNode = pPart;
              }
            else
              {
                mpRootNode = new CEvaluationNodeOperator(CEvaluationNode::S_MINUS, "-");
                mpRootNode->addChild(pPart);

                pK = it->value;
                ++it;
                pSpecies = it->vector;
                ++it;

                pPart = createMassActionPart(pK, pSpecies);

                mpRootNode->addChild(pPart);
              }
          }
      }
      break;

      case CEvaluationTree::MathExpression:
      case CEvaluationTree::Expression:
        // This cannot happen and is only here to satisfy the compiler.
        break;
    }

  compile();
}