Пример #1
0
Node* Node::predecessor() {//Poprzednik
	Node *p = this;
	if (this->left != NULL)
		return(maximal(p->left));

		throw std::exception("Wezel nie posiada poprzednika.");

};
Пример #2
0
void FastHessian::compute()
{
  // For each octave, only the filter sizes not already used for
  // smaller scales are added. This means that the (up to) four
  // interval layers for each octave will be at different points of
  // the response map. This mapping gives those indexes, corresponding
  // to the buildup in buildResponseMap().
  //
  // (Taken from the openSURF code).
  static const int filter_map [OCTAVES][INTERVALS] = {{0,1,2,3},
                                                      {1,3,4,5},
                                                      {3,5,6,7},
                                                      {5,7,8,9},
                                                      {7,9,10,11}};

  // start by clearing out any existing interest points and building
  // the Hessian response map.
  m_ipoints.clear();
  buildResponseMap();

  // Compute maxima by comparing points to the level above and below
  // them. The SURF article is quite vague on whether or not
  // comparison is made between different octaves. The SIFT article
  // does not mention this either. However, the opencv and the
  // opensurf implementations seem to agree that comparison is only
  // done within octaves, so this is the approach we take here.

  ResponseLayer *b,*m,*t;
  int o,i,x,y;

  // Loop through all octaves, and for octave, select m_interval-2
  // sets of top/middle/bottom. This does in practice mean that only 3
  // or 4 intervals pr octave make sense.
  for(o = 0; o < m_octaves; o++) {
    for(i = 0; i < m_intervals-2; i++) {
      b = m_layers.at(filter_map[o][i]);
      m = m_layers.at(filter_map[o][i+1]);
      t = m_layers.at(filter_map[o][i+2]);

      // Loop at the scale of the top-most (most sparse) layer
      for(y = 0; y < t->height(); y++) {
        for(x = 0; x < t->width(); x++) {
          Point pt(x,y);
          if(maximal(pt, b, m, t)) addPoint(pt, b, m, t);
        }
      }
    }
  }
}
int main(int argc, char* argv[])
{
	if ( argc != 4 )
	{	
		cout << "Usage: CMOrderedTreeMiner support input_file output_file" << endl;
		exit (1);
	}

	int support;
	istringstream iss(argv[1]);
	iss >> support;
	if(!iss)
	{
		cerr << "invalid argument, not an integer value" << endl;
		exit (1);
	}

	vector<int> frequency(1000,0); //assuming the max frequent tree size is 1000
	vector<int> checked(1000,0);
	vector<int> closed(1000,0);
	vector<int> maximal(1000,0);

	currentPatternTree.initialSize();
	time_t start_time;
	time_t stop_time;

	/******************************************************************
	step1: read in the database, and find the MIN_VERTEX and MAX_VERTEX
	******************************************************************/
	string inputFile = argv[2];
	string outputFile = argv[3];

	ofstream outFile(outputFile.c_str());
	if(!outFile) {
		cerr << "cannot open OUTPUT file!" << endl;
		exit(1);
	}

	ifstream inFile(inputFile.c_str());
	if(!inFile) {
		cerr << "cannot open INPUT file!" << endl;
		exit(1);
	}

	vector<TextTree> database;
	int myTid = 0;
	while ( !inFile.eof() ) {
		TextTree tt;
		inFile >> tt;
		if ( !inFile.eof() ) {
			tt.tid = myTid++;
			for ( short i = 0; i < tt.vNumber; i++ ) {
				if ( tt.vLabel[i] < MIN_VERTEX ) MIN_VERTEX = tt.vLabel[i];
				if ( tt.vLabel[i] > MAX_VERTEX ) MAX_VERTEX = tt.vLabel[i];
			}
			database.push_back(tt);
		}
	}
	inFile.close();

	/******************************************************************
	step2.1: scan the database once, find frequent node labels
	******************************************************************/
	vector<bool> isFrequent(MAX_VERTEX - MIN_VERTEX + 1, false);
	map<short,int> count;
	map<short,int>::iterator pos;

	start_time = time(0);

	for ( int i = 0; i < database.size(); i++ ) {
		vector<bool> isVisited(MAX_VERTEX - MIN_VERTEX + 1, false);
		for ( short j = 0; j < database[i].vNumber; j++ ) {
			short temp = database[i].vLabel[j] - MIN_VERTEX;
			if ( !isVisited[temp] ) {
				isVisited[temp] = true;
				pos = count.find(temp);
				if ( pos != count.end() )
					count[temp]++;
				else
					count.insert(make_pair(temp, 1));
			}
		}
	}
	for ( int i = 0; i < isFrequent.size(); i++ ) {
		if ( count[i] >= support ) isFrequent[i] = true;
	}

	/******************************************************************
	step2.2: scan the database another time, to get occurrenceList for all 
	frequent nodes 
	******************************************************************/
	map<short,OccLongList> occLongList;
	map<short,OccLongList>::iterator pos2;
	vector<short> dummy;
	for ( int i = 0; i < database.size(); i++ ) {
		for ( short j = 0; j < database[i].vNumber; j++ ) {
			if ( isFrequent[database[i].vLabel[j] - MIN_VERTEX] == true ) {
				occLongList[database[i].vLabel[j] - MIN_VERTEX].insert(i,dummy,j);
			}
		}
	}

	/******************************************************************
	step2.3: explore each frequent item 
	******************************************************************/
	for ( pos2 = occLongList.begin(); pos2 != occLongList.end(); ++pos2 ) {
		if ( pos2->second.mySupport >= support ) {
			currentPatternTree.addRightmost(pos2->first + MIN_VERTEX,0);
			pos2->second.explore(isFrequent,database,support,checked,closed,maximal);
			currentPatternTree.deleteRightmost();
		}
	}

	stop_time = time(0);

	/******************************************************************
	step2.4: output the results 
	******************************************************************/
	for ( short j = 0; j < 1000; j++ ) {
		if ( checked[j] > 0 ) {
			outFile << "number of checked " << j << " trees: " << checked[j] << endl;
		}
	}
	outFile << endl << "************************" << endl;
	for ( short j = 0; j < 1000; j++ ) {
		if ( closed[j] > 0 ) {
			outFile << "number of closed " << j << " trees: " << closed[j] << endl;
		}
	}
	outFile << endl << "************************" << endl;
	for ( short j = 0; j < 1000; j++ ) {
		if ( maximal[j] > 0 ) {
			outFile << "number of maximal " << j << " trees: " << maximal[j] << endl;
		}
	}

	outFile << endl;
	outFile << "Total Running Time: " << difftime(stop_time, start_time) << endl;

	outFile.close();


	return 0;
}
Пример #4
0
/* create mesh from a vector of nodes, element list in format =>
 * {nuber of nodes, node0, node1, ..., material}, {REPEAT}, ..., 0 (end of list); and surface colors in format =>
 * global surface, {number of nodes, node0, node1, ..., surface}, {REPEAT}, ..., 0 (end of list); */
MESH_DATA* MESH_Create (REAL (*nodes) [3], int *elements, int *surfaces)
{
  int maximal_node,
      minimal_node,
      elements_count,
      faces_count,
      temp, *eleptr, n;
  REAL (*node) [3];
  MEM *elemem,
      facmem,
      mapmem;
  ELEMENT *ele, *enx, *elist;
  FACE *fac, *cac, *gac, *flist;
  MAP *faces, *smap;
  MESH_DATA *msh;
  
  maximal_node = 0;
  minimal_node = INT_MAX;
  elements_count = 0;
  faces_count = 0;

  /* create mesh storage */
  ERRMEM (msh = static_cast<MESH_DATA*>(MEM_CALLOC (sizeof (MESH_DATA))));
  elemem = &msh->elemem;
 
  /* calculate elements */ 
  for (eleptr = elements; eleptr [0]; eleptr += (eleptr [0]+2)) elements_count ++;

  MEM_Init (elemem, sizeof (ELEMENT), elements_count);
  MEM_Init (&facmem, sizeof (FACE), MEMCHUNK);
  MEM_Init (&mapmem, sizeof (MAP), MEMCHUNK);
  MEM_Init (&msh->mapmem, sizeof (MAP), MIN (elements_count, MEMCHUNK));

  elist = NULL;
  flist = NULL;
  faces = NULL;

  /* create elements list & face adjacency map */
  for (eleptr = elements; eleptr [0]; eleptr += (eleptr [0]+2))
  {
    ASSERT (
      eleptr [0] == 4 || /* tetrahedron */
      eleptr [0] == 5 || /* pyramid */
      eleptr [0] == 6 || /* wedge */
      eleptr [0] == 8,   /* hexahedron */
      "ERROR: unsupported element type");

    ele = create_element (elemem, eleptr);
    flist = create_faces (&facmem, &mapmem, &faces, ele, flist);
    ele->next = elist;
    elist = ele;

    /* node number extrema */
    temp = maximal (eleptr);
    if (temp > maximal_node)
      maximal_node = temp;
    temp = minimal (eleptr);
    if (temp < minimal_node)
      minimal_node = temp;
  }

  /* calculate faces */
  for (fac = flist; fac; fac = fac->next)
    if (fac->ele) faces_count ++;

  /* alocate additional storage */
  MEM_Init (&msh->facmem, sizeof (FACE), faces_count);
  msh->nodes_count = (maximal_node - minimal_node + 1);
  ERRMEM (msh->nodes = static_cast<REAL(*)[3]>(malloc (sizeof (REAL [3]) * (msh->nodes_count))));
  msh->surfeles_count = msh->bulkeles_count = 0;
  msh->surfeles = msh->bulkeles = NULL;

  /* set up elements */
  for (ele = elist; ele; ele = enx)
  {
    enx = ele->next;

    if (minimal_node > 0) /* impose 0-based indexing */
    {
      for (temp = 0; temp < ele->type; temp ++)
	ele->nodes [temp] -= minimal_node;
    }

    ele->prev = NULL;
   
    if (ele->neighs < neighs (ele->type)) /* surface element */
    {
      msh->surfeles_count ++;
      ele->next = msh->surfeles;
      if (msh->surfeles) msh->surfeles->prev = ele;
      msh->surfeles = ele;
    }
    else /* bulk element */
    {
      msh->bulkeles_count ++;
      ele->next = msh->bulkeles;
      if (msh->bulkeles) msh->bulkeles->prev = ele;
      msh->bulkeles = ele;
    }
  }

  /* create surfaces map => skip first element of 'surfaces' == the global surface kind */
  for (eleptr = (surfaces + 1), smap = NULL, temp = 0;
    eleptr [0]; eleptr += (eleptr [0]+2), temp ++)
  {
    fac = static_cast<FACE*>(MEM_Alloc (&facmem));
    
    ASSERT (
      eleptr [0] == 3 || /* triangle */
      eleptr [0] == 4,   /* quad */
      "ERROR: unsupported face type");

    fac->type = eleptr [0];
    for (n = 0; n < eleptr [0]; n ++)
      fac->nodes [n] = eleptr [n+1];
    sort (fac->nodes, fac->nodes+fac->type-1);

    fac->color = eleptr [eleptr [0] + 1];
    MAP_Insert (&mapmem, &smap, fac, /* map by the type/nodes key */
      fac, face_compare);
  }

  /* set up nodes */
  for (temp = minimal_node,
       node = msh->nodes;
       temp <= maximal_node;
       temp ++, node ++)
  {
    COPY (nodes [temp], *node);
  }

  /* set up faces */
  for (fac = flist; fac; fac = fac->next)
  {
    if (fac->ele) /* see (***) */
    {
      ele = fac->ele;

      cac = static_cast<FACE*>(MEM_Alloc (&msh->facmem));
      setup_face (ele, fac->index, cac, 0); /* setup face nodes without sorting them */
      cac->index = fac->index;
      cac->ele = fac->ele;
      setup_normal (msh->nodes, cac); /* calculate outer spatial normal */
      cac->next = ele->faces; /* append element face list */
      ele->faces = cac;

      /* set the mapped surface kind if possible => otherwise the global one */
      gac = static_cast<FACE*>(MAP_Find (smap, fac, face_compare));
      cac->color = (gac ? gac->color : surfaces [0]);
    }
  }

  /* create mesh face list */
  for (ele = msh->surfeles; ele; ele = ele->next)
  {
    for (fac = ele->faces; fac; fac = fac->next)
    {
      fac->n = msh->faces;
      msh->faces = fac;
    }
  }

  /* clean up */
  MEM_Release (&facmem);
  MEM_Release (&mapmem);

  return msh;
}