예제 #1
0
파일: Neurons.cpp 프로젝트: allogn/TOUCH
Neurons Neurons::operator & (const Circle<Micron> & circle)
{
    CHECK_CONTAINER_MICROCIRCUIT_POINTER(*this);
    Neurons result(_microcircuit.lock());

    //! \todo Fix commented out code below. (TT)
    //result._description = _description + " within a radius of " + 
    //    boost::lexical_cast<const Word>(radius) + " from the center point ("
    // + 
    //    boost::lexical_cast<const Word>(circle.center().x()) + ", " +
    //    boost::lexical_cast<const Word>(circle.center().z()) + ")";

    for (Neurons::iterator i = begin(); i != end(); ++i )
    {
		const Neuron & neuron = * i;
        Micron distance =
            std::sqrt((neuron.position().x() - circle.center().x()) * 
                      (neuron.position().x() - circle.center().x()) + 
                      (neuron.position().z() - circle.center().z()) * 
                      (neuron.position().z() - circle.center().z()));
#ifndef NDEBUG
        std::cout << "Distance:" << distance << std::endl;
#endif

        if (distance <= circle.radius())
        {
#ifndef NDEBUG
            std::cout << "Neuron a" << neuron.gid() << " at position " 
                      << neuron.position() << " is within a radius of " 
                      << circle.radius() << std::endl;
#endif
            result.insert(i.ptr());
        }
#ifndef NDEBUG
        else
        {
            std::cout << "Neuron a" << neuron.gid() << " at position " 
                      << neuron.position() << " is NOT within a radius of " 
                      << circle.radius() << std::endl;
        }
#endif
    }
    return result;
}
예제 #2
0
int main(int argc, const char* argv[])
{
	/*
	 *  Build 48 Index with Links
	 */


	// Load Circuit
    Experiment experiment;
    experiment.open(blue_config_filename);
    Microcircuit & microcircuit = experiment.microcircuit();
    const Targets & targets = experiment.targets();
    const Cell_Target target = targets.cell_target("Column");
    microcircuit.load(target, NEURONS | MORPHOLOGIES);

    //Make Neuron Rtrees
    ISpatialIndex *neuronTrees[MORPHOLOGIES_COUNT];
    string *morphologyLabels[MORPHOLOGIES_COUNT];

    int cm=0;
    Morphologies & myMorphologies = microcircuit.morphologies();
    Morphologies::iterator myMorphologiesEnd = myMorphologies.end();
      for (Morphologies::iterator i = myMorphologies.begin(); i != myMorphologiesEnd; ++i)
      {
    	  morphologyLabels[cm] = i->label();
    	  neuronTrees[cm] = RTree::createNewRTree (createNewMemoryStorageManager(), 0.7, 127, 127, 3,RTree::RV_RSTAR,indexIdentifier);
    	  cm++;
      }

    Neurons & myNeurons = microcircuit.neurons();
    Neurons::iterator myNeuronsEnd = myNeurons.end();
    for (Neurons::iterator i = myNeurons.begin(); i != myNeuronsEnd; ++i)
    {
    	cm=0;
    	for (cm=0;cm<MORPHOLOGIES_COUNT;cm++)
    		if (strcmp(i->morphology().label(),morphologyLabels[cm])==0) break;

    	Transform_3D<Micron> trafo = i->global_transform();
    	Sections mySections = i->morphology().all_sections();
    	Sections::iterator mySectionsEnd = mySections.end();
    	for (Sections::iterator s = mySections.begin(); s != mySectionsEnd; ++s)
    	    {
    		 Segments segments = s->segments();
    		 Segments::const_iterator segments_end = segments.end();
    		 for (Segments::const_iterator j = segments.begin(); j != segments_end ; ++j)
    		     {
     			 vect plow, phigh;
     			 get_segment_mbr (*j, trafo, &plow, &phigh);
     			 SpatialIndex::Region mbr = SpatialIndex::Region(plow.data(),phigh.data(),3);

     			 std::stringstream strStream;
     			 strStream << i->gid() <<"-"<< s->id()<< "-" << j->id();
     			 neuronTrees[cm]->insertData (strStream.str().length(), (byte*)(strStream.str().c_str()), mbr, segmentid);
    		     }
    	    }
    }

    // Make Morphology Rtrees
    Morphologies & myMorphologies = microcircuit.morphologies();
    Morphologies::iterator myMorphologiesEnd = myMorphologies.end();
      for (Morphologies::iterator i = myMorphologies.begin(); i != myMorphologiesEnd; ++i)
      {
      	cout << "Indexing Morphology: " << i->label();
      	string baseName = i->label();
        IStorageManager* diskfile = StorageManager::createNewDiskStorageManager(baseName, 4096);
        ISpatialIndex *tree = RTree::createNewRTree (*diskfile, 0.7, 127, 127, 3,RTree::RV_RSTAR,indexIdentifier);
        indexIdentifier++; segmentid=0;

      	Sections mySections = i->all_sections();
      	Sections::iterator mySectionsEnd = mySections.end();
      	for (Sections::iterator s = mySections.begin(); s != mySectionsEnd; ++s)
      	{
            Segments segments = s->segments();
      		Segments::const_iterator segments_end = segments.end();
      		for (Segments::const_iterator j = segments.begin(); j != segments_end ; ++j)
      		{

      			Box<bbp::Micron> Mbr = AABBCylinder::calculateAABBForCylinder(j->begin().center(),
      								  j->begin().radius(),j->end().center(),j->begin().radius());

      			vect plow, phigh;

      			plow[0] = Mbr.center().x() - Mbr.dimensions().x() / 2;
      			phigh[0] = Mbr.center().x() + Mbr.dimensions().x() / 2;
      			plow[1] = Mbr.center().y() - Mbr.dimensions().y() / 2;
      			phigh[1] = Mbr.center().y() + Mbr.dimensions().y() / 2;
      			plow[2] = Mbr.center().z() - Mbr.dimensions().z() / 2;
      			phigh[2] = Mbr.center().z() + Mbr.dimensions().z() / 2;

				SpatialIndex::Region mbr = SpatialIndex::Region(plow.data(),phigh.data(),3);

      			std::stringstream strStream;
      			strStream << s->id()<< "-" << j->id();

      			tree->insertData (strStream.str().length(), (byte*)(strStream.str().c_str()), mbr, segmentid);
      			segmentid++;
      		}
      	}
      	cout << ".. Total Segments: " << segmentid << "\n";
        tree->~ISpatialIndex();
        diskfile->~IStorageManager();
      }


    // PRELOAD the Trees amd Neuron Morphology Mapping


    ISpatialIndex *neurons[NEURONS_COUNT];
    global_transformer *transforms[NEURONS_COUNT];

    int cm=0;
    int cn=0;
    string baseName = "";
    Morphologies & myMorphologies = microcircuit.morphologies();
    Neurons & myNeurons = microcircuit.neurons();

    cout << "PreLoading Mappings \n";
    Morphologies::iterator myMorphologiesEnd = myMorphologies.end();
      for (Morphologies::iterator m = myMorphologies.begin(); m != myMorphologiesEnd; ++m)
      {
    	  baseName = m->label();
    	  m->
          IStorageManager* diskfile = StorageManager::loadDiskStorageManager(baseName);
          trees[cm] = RTree::loadRTree(*diskfile, 1);

          std::cout << "Checking R-tree structure... ";
          if (!trees[cm]->isIndexValid()) std::cerr << "R-tree internal checks failed!\n"; else std::cout << "OK\n";
          IStatistics * tree_stats;
          trees[cm]->getStatistics (&tree_stats);
          cout << *tree_stats;

          Neurons::iterator myNeuronsEnd = myNeurons.end();
          for (Neurons::iterator n = myNeurons.begin(); n != myNeuronsEnd; ++n)
              {
        	  if (strcmp(n->morphology().label().c_str(),m->label().c_str())==0)
        		  {
        		  transforms[cn] = n->global_transform().inverse();
        		  neurons[cn] = trees[cm];
        		  }
        	  cn++;
        	  if (cn>=NEURONS_COUNT) break;
              }
          cn=0;cm++;
      }




	/*
	 *  Query the Index
	 */








}
예제 #3
0
int main(int argc, const char* argv[])
{
    const URI blue_config_filename(argv[1]);
    try {
    	// LOADING CURCUIT
        Experiment experiment;
        experiment.open(blue_config_filename);
        Microcircuit & microcircuit = experiment.microcircuit();
        const Targets & targets = experiment.targets();
        const Cell_Target target = targets.cell_target("Column");
        microcircuit.load(target, NEURONS | MORPHOLOGIES);

        // PRELOAD the Trees amd Neuron Morphology Mapping
        ISpatialIndex *trees[MORPHOLOGIES_COUNT];
        ISpatialIndex *neurons[NEURONS_COUNT];
        global_transformer *transforms[NEURONS_COUNT];

        int cm=0;
        int cn=0;
        string baseName = "";
        Morphologies & myMorphologies = microcircuit.morphologies();
        Neurons & myNeurons = microcircuit.neurons();

        cout << "PreLoading Mappings \n";
        Morphologies::iterator myMorphologiesEnd = myMorphologies.end();
          for (Morphologies::iterator m = myMorphologies.begin(); m != myMorphologiesEnd; ++m)
          {
        	  baseName = m->label();
              IStorageManager* diskfile = StorageManager::loadDiskStorageManager(baseName);
              trees[cm] = RTree::loadRTree(*diskfile, 1);

              std::cout << "Checking R-tree structure... ";
              if (!trees[cm]->isIndexValid()) std::cerr << "R-tree internal checks failed!\n"; else std::cout << "OK\n";
              IStatistics * tree_stats;
              trees[cm]->getStatistics (&tree_stats);
              cout << *tree_stats;

              Neurons::iterator myNeuronsEnd = myNeurons.end();
              for (Neurons::iterator n = myNeurons.begin(); n != myNeuronsEnd; ++n)
                  {
            	  if (strcmp(n->morphology().label().c_str(),m->label().c_str())==0)
            		  {
            		  transforms[cn] = n->global_transform().inverse();
            		  neurons[cn] = trees[cm];
            		  }
            	  cn++;
            	  if (cn>=NEURONS_COUNT) break;
                  }
              cn=0;cm++;
          }
          /*
          // SINGLE QUERY
          cout << "Start Querying \n";
          range_query_visitor visitor;
		  SpatialIndex::Region query;

		  micron_vector plow,phigh;
		  plow[0] = 0; plow[1] = 0; plow[2] = 0;
		  phigh[0]=90; phigh[1]=90; phigh[2]=90;

          for (int i=0;i<NEURONS_COUNT;i++)
          {
    		  get_transformed_cube_mbr(plow,phigh,*transforms[i],&query);
    		  neurons[i]->intersectsWithQuery(query,visitor);
    		  visitor.inc_neuron();
          }
          visitor.print_stats();
*/

          // PERFORMANCE EVALUATION RANDOM RANGE QUERIES
          {
          cout << "Start Range Query Analysis \n";
          range_query_visitor visitor;
  		  double plow[3],phigh[3];
  		  plow[0]  = 98.2538; plow[1]  = 1005.14; plow[2]  = 92.9046;
  		  phigh[0] = 452.301; phigh[1] = 1385.56; phigh[2] = 456.743;
  	 	  //plow[0]  = -1698.38; plow[1] = -1065.03; plow[2] = -1724.75;
  	 	 // phigh[0] = 2248.56;  phigh[1]= 1894.28;  phigh[2]= 2276.71;
          SpatialIndex::Region query_region = SpatialIndex::Region(plow,phigh,3);
  		  boost::mt11213b generator (42u);
  		  const double x[3] = {0.0, 0.0, 0.0};
  		  SpatialIndex::Point rnd_point1 (x, query_region.m_dimension);
  		  SpatialIndex::Point rnd_point2 (x, query_region.m_dimension);
  		  SpatialIndex::Region query;

  		  for (int j=0;j<QUERIES_FOR_ANALYSIS;j++)
  		  {
  		     for (size_t i = 0; i < query_region.m_dimension; i++)
  	 	     {
  	 	          boost::uniform_real<> uni_dist (query_region.m_pLow[i],query_region.m_pHigh[i]);
  	 	          boost::variate_generator<boost::mt11213b &,boost::uniform_real<> > uni(generator, uni_dist);
  	 	          rnd_point1.m_pCoords[i] = uni();

  	 	          boost::uniform_real<> uni_dist1 (rnd_point1.m_pCoords[i],query_region.m_pHigh[i]);
  	 	          boost::variate_generator<boost::mt11213b &,boost::uniform_real<> > uni1(generator, uni_dist1);
  	 	          rnd_point2.m_pCoords[i] = uni1();
  	 	     }
  			  visitor.new_query();
  			  visitor.reset_neuron();
  			  for (int i=0;i<NEURONS_COUNT;i++)
  			  {
  				  Vector_3D<Micron> low  = Vector_3D<Micron>((Micron)rnd_point1.m_pCoords[0],(Micron)rnd_point1.m_pCoords[1],(Micron)rnd_point1.m_pCoords[2]);
  				  Vector_3D<Micron> high = Vector_3D<Micron>((Micron)rnd_point2.m_pCoords[0],(Micron)rnd_point2.m_pCoords[1],(Micron)rnd_point2.m_pCoords[2]);
  				  get_transformed_cube_mbr(low,high,*transforms[i],&query);
  				  neurons[i]->intersectsWithQuery(query,visitor);
  			  }
  			  if (j%100==0) cout << "Queries Done: " << j << "\n";
  		  }
  		  visitor.print_stats();
          }
/*
          {
          // PERFORMANCE EVALUATION RANDOM POINT QUERIES
          cout << "Start Point Query Analysis \n";
          range_query_visitor visitor;
		  double plow[3],phigh[3];
		  //plow[0]  = 98.2538; plow[1]  = 1005.14; plow[2]  = 92.9046;
		 // phigh[0] = 452.301; phigh[1] = 1385.56; phigh[2] = 456.743;
  	 	  plow[0]  = -1698.38; plow[1] = -1065.03; plow[2] = -1724.75;
  	 	  phigh[0] = 2248.56;  phigh[1]= 1894.28;  phigh[2]= 2276.71;
          SpatialIndex::Region query_region = SpatialIndex::Region(plow,phigh,3);
		  boost::mt11213b generator (42u);

		  for (int j=0;j<QUERIES_FOR_ANALYSIS;j++)
		  {
			  const double x[3] = {0.0, 0.0, 0.0};
			  SpatialIndex::Point rnd_point (x, query_region.m_dimension);
			  SpatialIndex::Point tmp_point (x, query_region.m_dimension);

			  for (size_t i = 0; i < query_region.m_dimension; i++)
		      {
		          boost::uniform_real<> uni_dist (query_region.m_pLow[i],query_region.m_pHigh[i]);
		          boost::variate_generator<boost::mt11213b &,boost::uniform_real<> > uni(generator, uni_dist);
		          rnd_point.m_pCoords[i] = uni();
		      }
			  visitor.new_query();
			  visitor.reset_neuron();
			  //visitor.reset_stats();
			  for (int i=0;i<NEURONS_COUNT;i++)
			  {
				 // cout << "Point Query: (" <<  rnd_point.m_pCoords[0] << "," <<  rnd_point.m_pCoords[1] << "," << rnd_point.m_pCoords[2] << ") Transformed to: (";
				  Vector_3D<Micron> v = Vector_3D<Micron>((Micron)rnd_point.m_pCoords[0],(Micron)rnd_point.m_pCoords[1],(Micron)rnd_point.m_pCoords[2]);
				  v = *transforms[i]*v;
				  tmp_point.m_pCoords[0] = (double)v.x();
				  tmp_point.m_pCoords[1] = (double)v.y();
				  tmp_point.m_pCoords[2] = (double)v.z();
				 // cout <<  tmp_point.m_pCoords[0] << "," <<  tmp_point.m_pCoords[1] << "," << tmp_point.m_pCoords[2] << ")\n";
				  neurons[i]->pointLocationQuery(tmp_point,visitor);
			  }

		  }
		  visitor.print_stats();
          }
*/
          // PERFORMANCE EVALUATION RANDOM RANGE QUERIES





    }
    catch (Tools::Exception& e)
    {
      cout << e.what() << endl;
      exit(0);
    }
   // delete tree_stats;
    return 0;
}