int averageDeformationField(parameters list )
{
//read the reference volume
    typedef itk::Image< unsigned char , 3 > ImageType ;
    typedef itk::ImageFileReader< ImageType > ReaderType ;
    typedef typename ReaderType::Pointer ReaderTypePointer ;
    ReaderTypePointer readerReference ;
    readerReference = ReaderType::New() ;
    readerReference->SetFileName( list.referenceVolume.c_str() ) ;
    readerReference->UpdateOutputInformation() ;

      //set the size, origin, spacing,direction of the reference volume
      itk::Point< double , 3 > m_Origin ;
      itk::Vector< double , 3 > m_Spacing ;
      itk::Size< 3 > m_Size ;
      itk::Matrix< double , 3 , 3 > m_Direction;
       m_Spacing = readerReference->GetOutput()->GetSpacing() ;
       m_Size= readerReference->GetOutput()->GetLargestPossibleRegion().GetSize() ;
       m_Origin = readerReference->GetOutput()->GetOrigin() ;
       m_Direction = readerReference->GetOutput()->GetDirection() ;

       int n=list.deffieldtoaverage.size();
	typename DeformationImageType::Pointer fieldPointer1 ;
	DeformationFieldType dftype1 = HField ;
	if( !list.typeOfField[0].compare( "displacement" ) )
		{
			dftype1 = Displacement ;
		}
	//reads deformation field and if it is a h-field, it transforms it to a displacement field
	fieldPointer1 = readDeformationField( list.deffieldtoaverage[0] , dftype1 ) ;
	//Resample the deformation field so that it has the same properties as the reference image
      	ResampleDeformationField( fieldPointer1 ,m_Origin , m_Spacing ,m_Size ,m_Direction) ;
	
	typedef itk::ImageRegionIterator< DeformationImageType > DeformationConstIteratorType;
	DeformationConstIteratorType it1 (fieldPointer1,fieldPointer1->GetLargestPossibleRegion());
	//walk through all other deformation field volumes
	for(int i=1;i<n;i++)
	{
		
		typename DeformationImageType::Pointer fieldPointer2 ;
		//set if the field is a displacement or a H- field
		DeformationFieldType dftype2 = HField ;
		
		if( !list.typeOfField[i].compare( "displacement" ) )
		{
			dftype2 = Displacement ;
		}
		//reads deformation field and if it is a h-field, it transforms it to a displacement field
		fieldPointer2 = readDeformationField( list.deffieldtoaverage[i] , dftype2 ) ;
	 	
        	//Resample the deformation field so that it has the same properties as the reference image
      		ResampleDeformationField( fieldPointer2 ,m_Origin ,m_Spacing , m_Size ,m_Direction) ;
		
		it1.GoToBegin();
		DeformationConstIteratorType it2 (fieldPointer2,fieldPointer2->GetLargestPossibleRegion());
		it2.GoToBegin();
		itk::Vector<double,3> sum;sum[0]=0;sum[1]=0;sum[2]=0;
		while(!it1.IsAtEnd() && !it2.IsAtEnd())
		{
			sum+=(it1.Get())+(it2.Get());//sum displacements together	
			it1.Set(sum);
			sum[0]=0;sum[1]=0;sum[2]=0;
			++it1;++it2;
		}

	}
	it1.GoToBegin();
	itk::Vector<double,3> temp;
	while(!it1.IsAtEnd())
        {
		temp=(it1.Get())/n;//compute the average of displacements
		it1.Set(temp);
		++it1;
	}
	//Save HField
        typedef itk::ImageFileWriter< DeformationImageType > HFieldWriterType ;
        typedef typename HFieldWriterType::Pointer HFieldWriterTypePointer ;
        HFieldWriterTypePointer hfwriterAvg = HFieldWriterType::New() ;

        hfwriterAvg->SetInput( fieldPointer1 ) ;
        hfwriterAvg->SetFileName( list.outputAvg ) ;
	hfwriterAvg->UseCompressionOn();
        try
        {
          hfwriterAvg->Update() ;
        }
        catch( itk::ExceptionObject & Except )
        {
          std::cerr << "Writing output HField: Exception caught!"
                    << std::endl ;
          std::cerr << Except << std::endl ;
          return EXIT_FAILURE ;
        }

return EXIT_SUCCESS ;
}
Ejemplo n.º 2
0
/** This is a generic routine. It creates a new alignment by making a copy of the old one.
 */
void ImplAlignment::map(
		const HAlignment & other,
		const CombinationMode & mode )
{
	debug_func_cerr(5);

	const HAlignment copy = getClone();

	clear();

	AlignmentIterator it1(copy->begin());
	AlignmentIterator it1_end(copy->end());
	AlignmentIterator it2(other->begin());
	AlignmentIterator it2_end(other->end());

	while ( it1 != it1_end && it2 != it2_end )
	{

		const ResiduePair & x_pair = *it1;
		const ResiduePair & y_pair = *it2;

		Position map1 = NO_POS;
		Position value1 = NO_POS;

		Position map2 = NO_POS;
		Position value2 = NO_POS;

		switch (mode)
		{

		case RR:
			map1 = x_pair.mRow; value2 = x_pair.mCol;
			map2 = y_pair.mRow; value1 = y_pair.mCol;
			break;

		case CR:
			map1 = x_pair.mCol; value1 = x_pair.mRow;
			map2 = y_pair.mRow; value2 = y_pair.mCol;
			break;

		case RC:
			map1 = x_pair.mRow; value2 = x_pair.mCol;
			map2 = y_pair.mCol; value1 = y_pair.mRow;
			break;

		case CC:
			map1 = x_pair.mCol; value1 = x_pair.mRow;
			map2 = y_pair.mCol; value2 = y_pair.mRow;
			break;
		}

		assert( value1 != NO_POS);
		assert( value2 != NO_POS);

		debug_cerr( 5, "map1:" << map1 << " value1:" << value1 << " map2:" << map2 << " value2:" << value2 );

		if (map1 == map2)
		{
			addPair( ResiduePair(value1, value2, 0));
			++it1;
			++it2;
		}
		else
		{
			if (map1 < map2)
				++it1;
			else
				++it2;
		}

	}

	return;
}
Ejemplo n.º 3
0
bool urdf_traverser::helpers::getCommonParentPath(const std::string& p1, const std::string& p2, std::string& result)
{
    if (p1.empty() || p2.empty())
    {
        ROS_ERROR("Both p1 and p2 have to be set in getCommonParentPath()");
        return false;
    }
    boost::filesystem::path __p1(p1);
    boost::filesystem::path __p2(p2);
    bool correctAbsolute = __p1.is_relative() || __p2.is_relative();

    boost::filesystem::path _p1(boost::filesystem::absolute(__p1));
    boost::filesystem::path _p2(boost::filesystem::absolute(__p2));
    boost::filesystem::path buildPath;

    boost::filesystem::path::iterator it1(_p1.begin());
    boost::filesystem::path::iterator it1_end(_p1.end());
    boost::filesystem::path::iterator it2(_p2.begin());
    boost::filesystem::path::iterator it2_end(_p2.end());

    int p1Len = numDirectories(p1);
    int p2Len = numDirectories(p2);
    // ROS_INFO_STREAM("p1: "<<p1<<", p2: "<<p2);
    // ROS_INFO_STREAM("p1: "<<p1Len<<", p2: "<<p2Len);
    if (p2Len > p1Len)
    {
        //swap around paths
        boost::filesystem::path::iterator tmp(it2);
        it2 = it1;
        it1 = tmp;
        tmp = it2_end;
        it2_end = it1_end;
        it1_end = tmp;
    }

    --it1_end;  // make sure the iteration goes only until the previous-last
    // entry, because the last entry is either '.' or a filename
    for (; it1 != it1_end; ++it1, ++it2)
    {
        // ROS_INFO_STREAM("Comp "<<it1->string()<<", 2 "<<it2->string());
        if ((it2 == it2_end)
                || (*it1 != *it2))
        {
            break;
        }

        // append the directory
        buildPath /= *it1;

        // std::cout << buildPath.string() << std::endl;
    }
    if (!buildPath.empty())
    {
        result = buildPath.string();
        // make sure notation ends with separator.
        // Last element *will* be directory as no files
        // have been added in the loop.
        enforceDirectory(result, false);
        // If the current directory was used to build an absolute path, remove it again.
        if (correctAbsolute)
        {
            std::string currDir = boost::filesystem::current_path().string();
            urdf_traverser::helpers::enforceDirectory(currDir, false);
            if (!urdf_traverser::helpers::getSubdirPath(currDir, result, result))
            {
                ROS_ERROR_STREAM("Could not remove temporarily created current directory for absolute path");
                return false;
            }
        }
        return true;
    }
    return false;
}
Ejemplo n.º 4
0
void RegionLoad::UpdateView()
{
	/*
	Tests the intersection of all regions with the view (if moved) 
	Call CreateActors of the areas that began to intercept and    
	DestroyActors of the areas that are not more intercepting.
	*/
	
	//The coordinates changes solve the bug in activation-problem_view_parent.ged
	//(don't load left region)

	//Make sure view don't will shake
	KrImage *pImageView = GameControl::Get()->GetViewActor()->getImage();
	Axis *pAxis = GameControl::Get()->GetAxis();

	if(pImageView->IsInvalid(true)) 
	{
		//Solve the alpha14.ged bug
		pImageView->CalcCompositeTransform();
		engine->Tree()->Walk(pImageView, true, true);
	}
	else
	{
		pImageView->CalcTransform();
	}

	//Get view bounds
	KrRect rectView = pImageView->Bounds(), viewPos;

	//Get view in screen and axis coordinates
	KrVector2T< GlFixed > screen, axis;
	pImageView->ObjectToScreen(0, 0, &screen);
	pAxis->getImage()->ScreenToObject( screen.x.ToInt(), screen.y.ToInt(), &axis );

	//Make sure rect is (0, 0, ...)
	rectView.Translate(-rectView.xmin, -rectView.ymin);

	//Translate to correct position
	rectView.Translate(axis.x.ToInt(), axis.y.ToInt());


	//Solve the bug: "PocketPC don't load checkers.ged"
	viewPos.Set(rectView.xmin, rectView.ymin, 
				//zeroViewPos.x.ToInt(), zeroViewPos.y.ToInt(),
				0, 0);

	

	if(viewPos != viewPosAnt)
	{		
		MapRegions createdRegions, destroyedRegions;

/*#ifdef DEBUG
		GLOUTPUT( " View pos: (%ld, %ld)\n",  rectView.xmin, rectView.ymin);
#endif*/

		MapRegionsIterator it(regions);
		RegionLoad *pRegion;
		for( it.Begin(); !it.Done(); it.Next() )
		{
			pRegion = *it.Key();

			pRegion->getImage()->CalcTransform();
			KrRect rectRegion = pRegion->getImage()->Bounds();
			rectRegion.Translate(-rectRegion.xmin, -rectRegion.ymin);

			//To axis coordinate
			pRegion->getImage()->ObjectToScreen(0, 0, &screen);
			pAxis->getImage()->ScreenToObject( screen.x.ToInt(), screen.y.ToInt(), &axis );
			rectRegion.Translate(axis.x.ToInt(), axis.y.ToInt());

			//View and region in axis coordinates
			if(rectView.Intersect(rectRegion))
			{
				if(!pRegion->bRegionInView)
				{
					createdRegions.Add(pRegion, 1);
				}				
			}
			else
			{
				if(pRegion->bRegionInView)
				{
					destroyedRegions.Add(pRegion, 1);				
				}
			}
		}

		//Destroy actors from regions outside the view
		//Solve the Move to Region.ged when add the 'sad' actor to two default regions 
		//(some times)

		MapRegionsIterator it1(destroyedRegions);
		
		for(it1.Begin(); !it1.Done(); it1.Next())
		{
			pRegion = *it1.Key();
			
			pRegion->DestroyActors();
			if(defaultRegion == pRegion)
				InvalidateDefaultRegion();
		}

		//Call OnCreate after destroy old actors
		//Solve the Move to Region 2.ged actor move to a wrong position
		MapRegionsIterator it2(createdRegions);
		
		for(it2.Begin(); !it2.Done(); it2.Next())
		{
			pRegion = *it2.Key();			
			RegionLoad *pOldDefaultRegion = defaultRegion;
			SetDefaultRegion(pRegion);
			
			pRegion->CreateActors();
					
			RemoveCommonActorsFromOldDefaultRegion(pOldDefaultRegion);
		}
		
		viewPosAnt = viewPos;
	}






}
Ejemplo n.º 5
0
static void testluproblem(const ap::real_2d_array& a,
     int m,
     int n,
     double& diffpu,
     double& luerr)
{
    ap::real_2d_array t1;
    ap::real_2d_array t2;
    ap::real_2d_array t3;
    ap::integer_1d_array it1;
    ap::integer_1d_array it2;
    int i;
    int j;
    int k;
    double v;
    double mx;
    ap::real_2d_array a0;
    ap::integer_1d_array p0;

    mx = 0;
    for(i = 1; i <= m; i++)
    {
        for(j = 1; j <= n; j++)
        {
            if( ap::fp_greater(fabs(a(i,j)),mx) )
            {
                mx = fabs(a(i,j));
            }
        }
    }
    if( ap::fp_eq(mx,0) )
    {
        mx = 1;
    }
    
    //
    // Compare LU and unpacked LU
    //
    t1.setbounds(1, m, 1, n);
    for(i = 1; i <= m; i++)
    {
        ap::vmove(&t1(i, 1), &a(i, 1), ap::vlen(1,n));
    }
    ludecomposition(t1, m, n, it1);
    ludecompositionunpacked(a, m, n, t2, t3, it2);
    for(i = 1; i <= m; i++)
    {
        for(j = 1; j <= ap::minint(m, n); j++)
        {
            if( i>j )
            {
                diffpu = ap::maxreal(diffpu, fabs(t1(i,j)-t2(i,j))/mx);
            }
            if( i==j )
            {
                diffpu = ap::maxreal(diffpu, fabs(1-t2(i,j))/mx);
            }
            if( i<j )
            {
                diffpu = ap::maxreal(diffpu, fabs(0-t2(i,j))/mx);
            }
        }
    }
    for(i = 1; i <= ap::minint(m, n); i++)
    {
        for(j = 1; j <= n; j++)
        {
            if( i>j )
            {
                diffpu = ap::maxreal(diffpu, fabs(0-t3(i,j))/mx);
            }
            if( i<=j )
            {
                diffpu = ap::maxreal(diffpu, fabs(t1(i,j)-t3(i,j))/mx);
            }
        }
    }
    for(i = 1; i <= ap::minint(m, n); i++)
    {
        diffpu = ap::maxreal(diffpu, fabs(double(it1(i)-it2(i))));
    }
    
    //
    // Test unpacked LU
    //
    ludecompositionunpacked(a, m, n, t1, t2, it1);
    t3.setbounds(1, m, 1, n);
    k = ap::minint(m, n);
    for(i = 1; i <= m; i++)
    {
        for(j = 1; j <= n; j++)
        {
            v = ap::vdotproduct(t1.getrow(i, 1, k), t2.getcolumn(j, 1, k));
            t3(i,j) = v;
        }
    }
    for(i = ap::minint(m, n); i >= 1; i--)
    {
        if( i!=it1(i) )
        {
            for(j = 1; j <= n; j++)
            {
                v = t3(i,j);
                t3(i,j) = t3(it1(i),j);
                t3(it1(i),j) = v;
            }
        }
    }
    for(i = 1; i <= m; i++)
    {
        for(j = 1; j <= n; j++)
        {
            luerr = ap::maxreal(luerr, fabs(a(i,j)-t3(i,j))/mx);
        }
    }
    
    //
    // Test 0-based LU
    //
    t1.setbounds(1, m, 1, n);
    for(i = 1; i <= m; i++)
    {
        ap::vmove(&t1(i, 1), &a(i, 1), ap::vlen(1,n));
    }
    ludecomposition(t1, m, n, it1);
    a0.setbounds(0, m-1, 0, n-1);
    for(i = 0; i <= m-1; i++)
    {
        for(j = 0; j <= n-1; j++)
        {
            a0(i,j) = a(i+1,j+1);
        }
    }
    rmatrixlu(a0, m, n, p0);
    for(i = 0; i <= m-1; i++)
    {
        for(j = 0; j <= n-1; j++)
        {
            diffpu = ap::maxreal(diffpu, fabs(a0(i,j)-t1(i+1,j+1)));
        }
    }
    for(i = 0; i <= ap::minint(m-1, n-1); i++)
    {
        diffpu = ap::maxreal(diffpu, fabs(double(p0(i)+1-it1(i+1))));
    }
}
Scalar AdaptiveSparseGrid<Scalar,UserVector>::refine_grid(
	typename std::multimap<Scalar,std::vector<int> > & activeIndex, 
	std::set<std::vector<int> > & oldIndex, 
	UserVector & integralValue,
	CubatureTensorSorted<Scalar> & cubRule,
	Scalar globalErrorIndicator,
	AdaptiveSparseGridInterface<Scalar,UserVector> & problem_data) {

  TEUCHOS_TEST_FOR_EXCEPTION((activeIndex.empty()),std::out_of_range,
              ">>> ERROR (AdaptiveSparseGrid): Active Index set is empty.");  

  int dimension = problem_data.getDimension();
  std::vector<EIntrepidBurkardt> rule1D; problem_data.getRule(rule1D);
  std::vector<EIntrepidGrowth> growth1D; problem_data.getGrowth(growth1D);

  // Initialize Flags
  bool maxLevelFlag     = true;
  bool isAdmissibleFlag = true;

  // Initialize Cubature Rule
  Teuchos::RCP<UserVector> s = integralValue.Create();

  // Initialize iterator at end of inOldIndex
  std::set<std::vector<int> >::iterator it1(oldIndex.end());  

  // Initialize iterator at end of inActiveIndex
  typename std::multimap<Scalar,std::vector<int> >::iterator it;

  // Obtain Global Error Indicator as sum of key values of inActiveIndex
  Scalar eta = globalErrorIndicator;

  // Select Index to refine
  it = activeIndex.end(); it--;        // Decrement to position of final value 
  Scalar G               = it->first;  // Largest Error Indicator is at End
  eta                   -= G;          // Update global error indicator
  std::vector<int> index = it->second; // Get Corresponding index
  activeIndex.erase(it);               // Erase Index from active index set
  // Insert Index into old index set
  oldIndex.insert(it1,index); it1 = oldIndex.end(); 
  
  // Refinement process
  for (int k=0; k<dimension; k++) {
    index[k]++; // index + ek
    // Check Max Level
    maxLevelFlag = problem_data.max_level(index);
    if (maxLevelFlag) {
      // Check Admissibility
      isAdmissibleFlag = isAdmissible(index,k,oldIndex,problem_data);
      if (isAdmissibleFlag) { // If admissible
	// Build Differential Quarature Rule
	CubatureTensorSorted<Scalar> diffRule(0,dimension);
	build_diffRule(diffRule,index,problem_data);
	
	// Apply Rule to function
	problem_data.eval_cubature(*s,diffRule);
	
	// Update integral value
	integralValue.Update(*s);
	
	// Update local error indicator and index set
	G  = problem_data.error_indicator(*s); 	
	if (activeIndex.end()!=activeIndex.begin()) 
	  activeIndex.insert(activeIndex.end()--,
			   std::pair<Scalar,std::vector<int> >(G,index));
	else
	  activeIndex.insert(std::pair<Scalar,std::vector<int> >(G,index));
		
	// Update global error indicators
	eta += G;

	// Update adapted quadrature rule nodes and weights
	cubRule.update(1.0,diffRule,1.0);
      }
    }
    else { // Max Level Exceeded 
      //std::cout << "Maximum Level Exceeded" << std::endl;
    }
    index[k]--;
  }
  return eta;
}
Ejemplo n.º 7
0
std::array<unsigned long,vcp<4,1,1>::element_count()> const vcp<4,1,1>::generate_vector( const_vertex_iterator v1, const_vertex_iterator v2 ) {
	std::array<unsigned long,element_count()> counts = {{0}};
	
	std::size_t v1v2( V1V2 * OUT * g.out_edge_exists( v1, v2 ) + V1V2 * IN * g.in_edge_exists( v1, v2 ) );
	
	unsigned long connections( 0 );
	unsigned long amutuals( 0 );
	unsigned long gaps( 0 );
	
	// compose ordered list of v3 candidates
	const_edge_iterator v1_out_neighbors_it( g.out_neighbors_begin( v1 ) );
	const_edge_iterator v1_out_neighbors_end( g.out_neighbors_end( v1 ) );
	const_edge_iterator v1_in_neighbors_it( g.in_neighbors_begin( v1 ) );
	const_edge_iterator v1_in_neighbors_end( g.in_neighbors_end( v1 ) );
	const_edge_iterator v2_out_neighbors_it( g.out_neighbors_begin( v2 ) );
	const_edge_iterator v2_out_neighbors_end( g.out_neighbors_end( v2 ) );
	const_edge_iterator v2_in_neighbors_it( g.in_neighbors_begin( v2 ) );
	const_edge_iterator v2_in_neighbors_end( g.in_neighbors_end( v2 ) );
	assert( MAX_NEIGHBORS > (v1_out_neighbors_end-v1_out_neighbors_it)+(v1_in_neighbors_end-v1_in_neighbors_it)+(v2_out_neighbors_end-v2_out_neighbors_it)+(v2_in_neighbors_end-v2_in_neighbors_it) );
	std::pair<const_vertex_iterator,unsigned short>* v3Vertices_begin( &v3Vertices[0] );
	std::pair<const_vertex_iterator,unsigned short>* v3Vertices_end( &v3Vertices[0] );
	std::pair<const_edge_iterator,directedness_value> min1( next_union_element( v1_out_neighbors_it, v1_out_neighbors_end, v1_in_neighbors_it, v1_in_neighbors_end ) );
	std::pair<const_edge_iterator,directedness_value> min2( next_union_element( v2_out_neighbors_it, v2_out_neighbors_end, v2_in_neighbors_it, v2_in_neighbors_end ) );
	while( min1.first != v1_in_neighbors_end && min2.first != v2_in_neighbors_end ) {
		if( g.target_of( min1.first ) < g.target_of( min2.first ) ) {
			if( g.target_of( min1.first ) != v2 ) {
				++connections;
				++gaps;
				if( min1.second < 3 ) {
					++amutuals;
				}
				v3Vertices_end->first = g.target_of( min1.first );
				v3Vertices_end->second = v1v2 + V1V3 * min1.second;
				++v3Vertices_end;
			}
			min1 = next_union_element( v1_out_neighbors_it, v1_out_neighbors_end, v1_in_neighbors_it, v1_in_neighbors_end );
		} else if( g.target_of( min1.first ) > g.target_of( min2.first ) ) {
			if( g.target_of( min2.first ) != v1 ) {
				++connections;
				++gaps;
				if( min2.second < 3 ) {
					++amutuals;
				}
				v3Vertices_end->first = g.target_of( min2.first );
				v3Vertices_end->second = v1v2 + V2V3 * min2.second;
				++v3Vertices_end;
			}
			min2 = next_union_element( v2_out_neighbors_it, v2_out_neighbors_end, v2_in_neighbors_it, v2_in_neighbors_end );
		} else { // the next neighbor is shared by both v1 and v2, so it cannot be either and we do not need to check to exclude it
			connections += 2;
			if( min1.second < 3 ) {
				++amutuals;
			}
			if( min2.second < 3 ) {
				++amutuals;
			}
		 	v3Vertices_end->first = g.target_of( min1.first );
		 	v3Vertices_end->second = v1v2 + V1V3 * min1.second + V2V3 * min2.second;
			++v3Vertices_end;
			min1 = next_union_element( v1_out_neighbors_it, v1_out_neighbors_end, v1_in_neighbors_it, v1_in_neighbors_end );
			min2 = next_union_element( v2_out_neighbors_it, v2_out_neighbors_end, v2_in_neighbors_it, v2_in_neighbors_end );
		}
	}
	while( min1.first != v1_in_neighbors_end ) {
		if( g.target_of( min1.first ) != v2 ) {
			++connections;
			++gaps;
			if( min1.second < 3 ) {
				++amutuals;
			}
			v3Vertices_end->first = g.target_of( min1.first );
			v3Vertices_end->second = v1v2 + V1V3 * min1.second;
			++v3Vertices_end;
		}
		min1 = next_union_element( v1_out_neighbors_it, v1_out_neighbors_end, v1_in_neighbors_it, v1_in_neighbors_end );
	}
	while( min2.first != v2_in_neighbors_end ) {
		if( g.target_of( min2.first ) != v1 ) {
			++connections;
			++gaps;
			if( min2.second < 3 ) {
				++amutuals;
			}
			v3Vertices_end->first = g.target_of( min2.first );
			v3Vertices_end->second = v1v2 + V2V3 * min2.second;
			++v3Vertices_end;
		}
		min2 = next_union_element( v2_out_neighbors_it, v2_out_neighbors_end, v2_in_neighbors_it, v2_in_neighbors_end );
	}

	unsigned long v3_count( v3Vertices_end-v3Vertices_begin );
	unsigned long v4_count( 0 );
	for( std::pair<const_vertex_iterator,unsigned short>* it1( v3Vertices_begin ); it1 != v3Vertices_end; ++it1 ) { // for each v3 vertex computed above
		const_edge_iterator v3_out_neighbors_it( g.out_neighbors_begin( it1->first ) );
		const_edge_iterator v3_out_neighbors_end( g.out_neighbors_end( it1->first ) );
		const_edge_iterator v3_in_neighbors_it( g.in_neighbors_begin( it1->first ) );
		const_edge_iterator v3_in_neighbors_end( g.in_neighbors_end( it1->first ) );
		unsigned long v4_local_count( 0 ); // keep track of how many v4 vertices are only the result of the neighbors of this v3
		std::pair<const_edge_iterator,directedness_value> min( next_union_element( v3_out_neighbors_it, v3_out_neighbors_end, v3_in_neighbors_it, v3_in_neighbors_end ) );
		for( std::pair<const_vertex_iterator,unsigned short>* it2( v3Vertices_begin ); it2 != v3Vertices_end; ++it2 ) {	
			while( min.first != v3_in_neighbors_end && g.target_of( min.first ) < it2->first ) {
				if( g.target_of( min.first ) != v1 && g.target_of( min.first ) != v2 ) {
					++v4_local_count;
					if( min.second < 3 ) {
						++amutuals;
					}
					++counts[ element_address( it1->second + V3V4 * min.second ) ];
				}
				min = next_union_element( v3_out_neighbors_it, v3_out_neighbors_end, v3_in_neighbors_it, v3_in_neighbors_end );
			}
			if( min.first == v3_in_neighbors_end || g.target_of( min.first ) > it2->first ) {
				if( it1->first < it2->first ) {
					unsigned short temp( it2->second - v1v2 );
					std::size_t contrib( 0 );
					contrib += V1V4 * (temp % V2V3);
					contrib += V2V4 * (temp / V2V3);
					++gaps;
					++counts[ element_address( it1->second + contrib ) ];
				}
			} else {
				if( it1->first < it2->first ) {
					unsigned short temp( it2->second - v1v2 );
					std::size_t contrib( 0 );
					contrib += V1V4 * (temp % V2V3);
					contrib += V2V4 * (temp / V2V3);
					++connections;
					if( min.second < 3 ) {
						++amutuals;
					}
					++counts[ element_address( it1->second + contrib + V3V4 * min.second  ) ];
				}
				min = next_union_element( v3_out_neighbors_it, v3_out_neighbors_end, v3_in_neighbors_it, v3_in_neighbors_end );
			}
		}
		while( min.first != v3_in_neighbors_end ) {
			if( g.target_of( min.first ) != v1 && g.target_of( min.first ) != v2 ) {
				++v4_local_count;
				if( min.second < 3 ) {
					++amutuals;
				}
				++counts[ element_address( it1->second + V3V4 * min.second ) ];
			}
			min = next_union_element( v3_out_neighbors_it, v3_out_neighbors_end, v3_in_neighbors_it, v3_in_neighbors_end );
		}
		v4_count += v4_local_count;
		connections += v4_local_count;
		gaps += 2*v4_local_count;
		counts[ element_address( it1->second ) ] += g.vertex_count() - 2 - v3_count - v4_local_count;
	}
		
	// account for the least connected substructures
	counts[ element_address( v1v2+OUT*V3V4) ] = this->amutualPairs - (amutuals + static_cast<bool>(v1v2)); // out and in versions are isomorphically equivalent and do not need to be counted separately
	counts[ element_address( v1v2+BOTH*V3V4 ) ] = this->mutualPairs - (connections - amutuals);
	counts[ element_address( v1v2 ) ] = unconnected_pairs - (gaps + !static_cast<bool>(v1v2)) - (2 + v3_count) * (g.vertex_count() - 2 - v3_count) + 3 * v4_count;
	
	return counts;
}
Ejemplo n.º 8
0
void AddArtifactsToDwiImageFilter< TPixelType >
::GenerateData()
{
    if (m_UseConstantRandSeed)  // always generate the same random numbers?
        m_RandGen->SetSeed(0);
    else
        m_RandGen->SetSeed();

    m_StartTime = clock();
    m_StatusText = "Starting simulation\n";

    typename InputImageType::Pointer inputImage  = static_cast< InputImageType* >( this->ProcessObject::GetInput(0) );
    itk::ImageRegion<3> inputRegion = inputImage->GetLargestPossibleRegion();

    typename itk::ImageDuplicator<InputImageType>::Pointer duplicator = itk::ImageDuplicator<InputImageType>::New();
    duplicator->SetInputImage( inputImage );
    duplicator->Update();
    typename InputImageType::Pointer outputImage = duplicator->GetOutput();

    // is input slize size even?
    int xMax=inputRegion.GetSize(0); int yMax=inputRegion.GetSize(1);
    if ( xMax%2 == 1 )
        xMax += 1;
    if ( yMax%2 == 1 )
        yMax += 1;

    // create slice object
    typename SliceType::Pointer slice = SliceType::New();
    ImageRegion<2> sliceRegion;
    sliceRegion.SetSize(0, xMax);
    sliceRegion.SetSize(1, yMax);
    slice->SetLargestPossibleRegion( sliceRegion );
    slice->SetBufferedRegion( sliceRegion );
    slice->SetRequestedRegion( sliceRegion );
    slice->Allocate();
    slice->FillBuffer(0.0);

    ImageRegion<2> upsampledSliceRegion;
    if ( m_Parameters.m_SignalGen.m_DoAddGibbsRinging)
    {
        upsampledSliceRegion.SetSize(0, xMax*2);
        upsampledSliceRegion.SetSize(1, yMax*2);
    }

    m_Parameters.m_SignalGen.m_SignalScale = 1;
    m_Parameters.m_SignalGen.m_DoSimulateRelaxation = false;

    if ( m_Parameters.m_SignalGen.m_Spikes>0 ||  m_Parameters.m_SignalGen.m_FrequencyMap.IsNotNull() ||  m_Parameters.m_SignalGen.m_KspaceLineOffset>0.0 ||  m_Parameters.m_SignalGen.m_DoAddGibbsRinging ||  m_Parameters.m_SignalGen.m_EddyStrength>0 ||  m_Parameters.m_SignalGen.m_CroppingFactor<1.0)
    {
        ImageRegion<3> croppedRegion = inputRegion; croppedRegion.SetSize(1, croppedRegion.GetSize(1)* m_Parameters.m_SignalGen.m_CroppingFactor);
        itk::Point<double,3> shiftedOrigin = inputImage->GetOrigin(); shiftedOrigin[1] += (inputRegion.GetSize(1)-croppedRegion.GetSize(1))*inputImage->GetSpacing()[1]/2;

        outputImage = InputImageType::New();
        outputImage->SetSpacing( inputImage->GetSpacing() );
        outputImage->SetOrigin( shiftedOrigin );
        outputImage->SetDirection( inputImage->GetDirection() );
        outputImage->SetLargestPossibleRegion( croppedRegion );
        outputImage->SetBufferedRegion( croppedRegion );
        outputImage->SetRequestedRegion( croppedRegion );
        outputImage->SetVectorLength( inputImage->GetVectorLength() );
        outputImage->Allocate();
        typename InputImageType::PixelType temp;
        temp.SetSize(inputImage->GetVectorLength());
        temp.Fill(0.0);
        outputImage->FillBuffer(temp);

        int tempY=croppedRegion.GetSize(1);
        tempY += tempY%2;
        croppedRegion.SetSize(1, tempY);

        m_StatusText += this->GetTime()+" > Adjusting complex signal\n";
        if ( m_Parameters.m_SignalGen.m_FrequencyMap.IsNotNull())
            m_StatusText += "Simulating distortions\n";
        if ( m_Parameters.m_SignalGen.m_DoAddGibbsRinging)
            m_StatusText += "Simulating ringing artifacts\n";
        if ( m_Parameters.m_SignalGen.m_EddyStrength>0)
            m_StatusText += "Simulating eddy currents\n";
        if ( m_Parameters.m_SignalGen.m_Spikes>0)
            m_StatusText += "Simulating spikes\n";
        if ( m_Parameters.m_SignalGen.m_CroppingFactor<1.0)
            m_StatusText += "Simulating aliasing artifacts\n";
        if ( m_Parameters.m_SignalGen.m_KspaceLineOffset>0)
            m_StatusText += "Simulating ghosts\n";

        std::vector< unsigned int > spikeVolume;
        for (unsigned int i=0; i< m_Parameters.m_SignalGen.m_Spikes; i++)
            spikeVolume.push_back(m_RandGen->GetIntegerVariate()%inputImage->GetVectorLength());
        std::sort (spikeVolume.begin(), spikeVolume.end());
        std::reverse (spikeVolume.begin(), spikeVolume.end());
        FiberfoxParameters<double> doubleParam =  m_Parameters.CopyParameters<double>();

        m_StatusText += "0%   10   20   30   40   50   60   70   80   90   100%\n";
        m_StatusText += "|----|----|----|----|----|----|----|----|----|----|\n*";
        unsigned long lastTick = 0;
        boost::progress_display disp(inputImage->GetVectorLength()*inputRegion.GetSize(2));
        for (unsigned int g=0; g<inputImage->GetVectorLength(); g++)
        {
            std::vector< unsigned int > spikeSlice;
            while (!spikeVolume.empty() && spikeVolume.back()==g)
            {
                spikeSlice.push_back(m_RandGen->GetIntegerVariate()%inputImage->GetLargestPossibleRegion().GetSize(2));
                spikeVolume.pop_back();
            }
            std::sort (spikeSlice.begin(), spikeSlice.end());
            std::reverse (spikeSlice.begin(), spikeSlice.end());

            for (unsigned int z=0; z<inputRegion.GetSize(2); z++)
            {
                if (this->GetAbortGenerateData())
                {
                    m_StatusText += "\n"+this->GetTime()+" > Simulation aborted\n";
                    return;
                }

                std::vector< SliceType::Pointer > compartmentSlices;
                // extract slice from channel g
                for (unsigned int y=0; y<inputRegion.GetSize(1); y++)
                    for (unsigned int x=0; x<inputRegion.GetSize(0); x++)
                    {
                        typename SliceType::IndexType index2D;
                        index2D[0]=x; index2D[1]=y;
                        typename InputImageType::IndexType index3D;
                        index3D[0]=x; index3D[1]=y; index3D[2]=z;

                        SliceType::PixelType pix2D = (SliceType::PixelType)inputImage->GetPixel(index3D)[g];
                        slice->SetPixel(index2D, pix2D);
                    }

                if ( m_Parameters.m_SignalGen.m_DoAddGibbsRinging)
                {
                    itk::ResampleImageFilter<SliceType, SliceType>::Pointer resampler = itk::ResampleImageFilter<SliceType, SliceType>::New();
                    resampler->SetInput(slice);
                    resampler->SetOutputParametersFromImage(slice);
                    resampler->SetSize(upsampledSliceRegion.GetSize());
                    resampler->SetOutputSpacing(slice->GetSpacing()/2);
                    itk::NearestNeighborInterpolateImageFunction<SliceType, double>::Pointer nn_interpolator
                            = itk::NearestNeighborInterpolateImageFunction<SliceType, double>::New();
                    resampler->SetInterpolator(nn_interpolator);
                    resampler->Update();
                    typename SliceType::Pointer upslice = resampler->GetOutput();
                    compartmentSlices.push_back(upslice);
                }
                else
                    compartmentSlices.push_back(slice);

                // fourier transform slice
                typename ComplexSliceType::Pointer fSlice;

                itk::Size<2> outSize; outSize.SetElement(0, xMax); outSize.SetElement(1, croppedRegion.GetSize()[1]);
                typename itk::KspaceImageFilter< SliceType::PixelType >::Pointer idft = itk::KspaceImageFilter< SliceType::PixelType >::New();
                idft->SetUseConstantRandSeed(m_UseConstantRandSeed);
                idft->SetParameters(&doubleParam);
                idft->SetCompartmentImages(compartmentSlices);
                idft->SetDiffusionGradientDirection( m_Parameters.m_SignalGen.GetGradientDirection(g));
                idft->SetZ((double)z-(double)inputRegion.GetSize(2)/2.0);
                int numSpikes = 0;
                while (!spikeSlice.empty() && spikeSlice.back()==z)
                {
                    numSpikes++;
                    spikeSlice.pop_back();
                }
                idft->SetSpikesPerSlice(numSpikes);
                idft->Update();
                fSlice = idft->GetOutput();

                // inverse fourier transform slice
                typename ComplexSliceType::Pointer newSlice;
                typename itk::DftImageFilter< SliceType::PixelType >::Pointer dft = itk::DftImageFilter< SliceType::PixelType >::New();
                dft->SetInput(fSlice);
                dft->Update();
                newSlice = dft->GetOutput();

                // put slice back into channel g
                for (unsigned int y=0; y<outputImage->GetLargestPossibleRegion().GetSize(1); y++)
                    for (unsigned int x=0; x<outputImage->GetLargestPossibleRegion().GetSize(0); x++)
                    {
                        typename InputImageType::IndexType index3D;
                        index3D[0]=x; index3D[1]=y; index3D[2]=z;
                        typename InputImageType::PixelType pix3D = outputImage->GetPixel(index3D);
                        typename ComplexSliceType::IndexType index2D;
                        index2D[0]=x; index2D[1]=y;

                        ComplexSliceType::PixelType cPix = newSlice->GetPixel(index2D);
                        double signal = sqrt(cPix.real()*cPix.real()+cPix.imag()*cPix.imag());
                        if (signal>0)
                            signal = floor(signal+0.5);
                        else
                            signal = ceil(signal-0.5);

                        pix3D[g] = signal;
                        outputImage->SetPixel(index3D, pix3D);
                    }

                ++disp;
                unsigned long newTick = 50*disp.count()/disp.expected_count();
                for (unsigned int tick = 0; tick<(newTick-lastTick); tick++)
                    m_StatusText += "*";
                lastTick = newTick;
            }
        }
        m_StatusText += "\n\n";
    }

    if ( m_Parameters.m_NoiseModel!=NULL)
    {
        m_StatusText += this->GetTime()+" > Adding noise\n";
        m_StatusText += "0%   10   20   30   40   50   60   70   80   90   100%\n";
        m_StatusText += "|----|----|----|----|----|----|----|----|----|----|\n*";
        unsigned long lastTick = 0;

        ImageRegionIterator<InputImageType> it1 (outputImage, outputImage->GetLargestPossibleRegion());
        boost::progress_display disp(outputImage->GetLargestPossibleRegion().GetNumberOfPixels());
        while(!it1.IsAtEnd())
        {
            if (this->GetAbortGenerateData())
            {
                m_StatusText += "\n"+this->GetTime()+" > Simulation aborted\n";
                return;
            }

            ++disp;
            unsigned long newTick = 50*disp.count()/disp.expected_count();
            for (unsigned int tick = 0; tick<(newTick-lastTick); tick++)
                m_StatusText += "*";
            lastTick = newTick;

            typename InputImageType::PixelType signal = it1.Get();
            m_Parameters.m_NoiseModel->AddNoise(signal);
            it1.Set(signal);

            ++it1;
        }
        m_StatusText += "\n\n";
    }

    this->SetNthOutput(0, outputImage);
    m_StatusText += "Finished simulation\n";
    m_StatusText += "Simulation time: "+GetTime();
}
Scalar AdaptiveSparseGrid<Scalar,UserVector>::refine_grid(
   	         typename std::multimap<Scalar,std::vector<int> >  & indexSet, 
		 UserVector & integralValue,
		 AdaptiveSparseGridInterface<Scalar,UserVector> & problem_data) {
  
  int dimension = problem_data.getDimension();
  std::vector<EIntrepidBurkardt> rule1D; problem_data.getRule(rule1D);
  std::vector<EIntrepidGrowth> growth1D; problem_data.getGrowth(growth1D);
  
  // Copy Multimap into a Set for ease of use
  typename std::multimap<Scalar,std::vector<int> >::iterator it;
  std::set<std::vector<int> > oldSet;
  std::set<std::vector<int> >::iterator it1(oldSet.begin());
  for (it=indexSet.begin(); it!=indexSet.end(); it++) {
    oldSet.insert(it1,it->second);
    it1++;
  }
  indexSet.clear();
  
  // Find Possible Active Points
  int flag = 1;
  std::vector<int> index(dimension,0);
  typename std::multimap<Scalar,std::vector<int> > activeSet;
  for (it1=oldSet.begin(); it1!=oldSet.end(); it1++) {
    index = *it1;
    for (int i=0; i<dimension; i++) {
      index[i]++;
      flag = (int)(!oldSet.count(index));
      index[i]--;
      if (flag) {
	activeSet.insert(std::pair<Scalar,std::vector<int> >(1.0,index));
	oldSet.erase(it1);
	break;
      }
    }
  }

  // Compute local and global error indicators for active set
  typename std::multimap<Scalar,std::vector<int> >::iterator it2;
  Scalar eta = 0.0;
  Scalar G   = 0.0;
  Teuchos::RCP<UserVector> s = integralValue.Create();
  for (it2=activeSet.begin(); it2!=activeSet.end(); it2++) {
    // Build Differential Quarature Rule
    index = it2->second;
    CubatureTensorSorted<Scalar> diffRule(0,dimension);
    build_diffRule(diffRule,index,problem_data);
    
    // Apply Rule to function
    problem_data.eval_cubature(*s,diffRule);
    
    // Update local error indicator and index set
    G  = problem_data.error_indicator(*s);
    activeSet.erase(it2);
    activeSet.insert(it2,std::pair<Scalar,std::vector<int> >(G,index));
    eta += G;
  }

  // Refine Sparse Grid
  eta = refine_grid(activeSet,oldSet,integralValue,eta,
		    dimension,rule1D,growth1D);

  // Insert New Active and Old Index sets into indexSet
  indexSet.insert(activeSet.begin(),activeSet.end());
  for (it1=oldSet.begin(); it1!=oldSet.end(); it1++) {
    index = *it1;
    indexSet.insert(std::pair<Scalar,std::vector<int> >(-1.0,index));
  }
    
  return eta;
}
Ejemplo n.º 10
0
void MainWindow::openFile(const QString & filename) {
    emit loadingNewMesh();
    auto package = std::make_shared<MeshPackage>();
    m_mesh.reset(readOBJtoSimplicialComplex<MeshType>(filename.toStdString()));
    std::cout << "Read a mesh with verts:faces: " << m_mesh->vertices().size()<< ":" << m_mesh->numSimplices() << std::endl;
    m_dec.reset(new decltype(m_dec)::element_type(*m_mesh));
    typedef typename MeshType::Vector Vector;

    package->vertices = m_mesh->vertices();//copy here so we can normalize coordinates
    package->indices = mtao_internal::template simplicesToRenderable<2>(*m_mesh);
    package->facevertices.resize(package->indices.size());
    package->faceindices.resize(package->indices.size());
    package->edgeindices = mtao_internal::simplicesToRenderable<1>(*m_mesh);
    package->edgevertices.resize(package->edgeindices.size());



    int i;


    auto& verts = package->vertices;
    auto& packed_indices = package->indices;
    auto& faceverts = package->facevertices;
    auto& faceindices = package->faceindices;
    auto& edgeindices = package->edgeindices;
    auto& edgeverts = package->edgevertices;

    //    mtao::normalizeInPlace(verts);//Normalize!!
    std::cout << "Normalizing vertices..." << std::endl;
    m_bbox = mtao::getBoundingBox(verts);
    mtao::normalizeToBBoxInPlace(verts,m_bbox);

    std::cout << "Writing primal verts" << std::endl;
    std::transform(packed_indices.cbegin(), packed_indices.cend(), faceverts.begin(),
                   [&verts](const unsigned int ind)->typename std::remove_reference<decltype(faceverts)>::type::value_type
    {
        return verts[ind];
    });

    i=0;
    std::cout << "Writing primal face indices" << std::endl;
    for(unsigned int & ind: faceindices)
    {
        ind = i++;
    }

    std::cout << "Writing primal edge vertices" << std::endl;
    std::transform(edgeindices.cbegin(), edgeindices.cend(), edgeverts.begin(),
                   [&verts](const unsigned int ind)->typename std::remove_reference<decltype(edgeverts)>::type::value_type
    {
        return verts[ind];
    });

    i=0;
    std::cout << "Writing primal edge indices" << std::endl;
    for(unsigned int & ind: edgeindices)
    {
        ind = i++;
    }





    std::cout << "Writing dual quantities" << std::endl;
    auto& dual_vertices = package->dual_vertices;
    auto& dual_indices = package->dual_indices;
    auto& dual_edgeindices = package->dual_edgeindices;
    auto& dual_edgeverts = package->dual_edgevertices;
    auto& dual_faceindices = package->dual_faceindices;
    auto& dual_faceverts = package->dual_facevertices;//blarg! can't autosize because this might turn out to be stupidly sophisticated

    dual_vertices.resize(
                m_mesh->template numSimplices<2>() +
                m_mesh->template numSimplices<1>() +
                m_mesh->template numSimplices<0>()
                );
    int offset2 = 0;//offset1 + m_mesh->template numSimplices<1>();
    int offset1 = m_mesh->template numSimplices<2>();
    int offset0 = offset1 + m_mesh->template numSimplices<1>();
    dual_edgeindices.resize(2*m_mesh->template numSimplices<1>());
    dual_edgeverts.resize(dual_edgeindices.size());


    typedef typename decltype(m_dec)::element_type::SparseMatrixColMajor SparseMatrix;
    const SparseMatrix & d0 = m_dec->template d<0>().expr;
    const SparseMatrix & d1 = m_dec->template d<1>().expr;





    package->num_dual_verts = m_mesh->template numSimplices<2>();

    std::cout << "Writing dual verts" << std::endl;
    for(auto&& s: m_mesh->template simplices<2>()) {
        dual_vertices[s.Index()+offset2] = s.Center();
    }

    for(auto&& s: m_mesh->template simplices<1>()) {
        dual_vertices[s.Index()+offset1] = s.Center();
    }

    for(auto&& s: m_mesh->template simplices<0>()) {
        dual_vertices[s.Index()+offset0] = s.Center();
    }

    std::cout << "Writing dual mesh indices" << std::endl;
    for(int i=0; i < m_mesh->template simplices<0>().size(); ++i) {
        auto&& s0 = m_mesh->template simplex<0>(i);

        for(SparseMatrix::InnerIterator it1(d0, s0.Index()); it1; ++it1) {
            auto&& s1 = m_mesh->template simplex<1>(it1.row());

            for(SparseMatrix::InnerIterator it2(d1, s1.Index()); it2; ++it2) {
                auto&& s2 = m_mesh->template simplex<2>(it2.row());
                dual_indices.push_back(s0.Index()+offset0);
                dual_indices.push_back(s1.Index()+offset1);
                dual_indices.push_back(s2.Index()+offset2);
            }
        }
    }



    std::cout << "Writing dual edge indices" << std::endl;
    for(int i=0; i < m_mesh->template simplices<1>().size(); ++i) {
        auto&& s = m_mesh->template simplex<1>(i);
        SparseMatrix::InnerIterator it(d1, s.Index());
        if(!it) continue;
        auto&& s1 = m_mesh->template simplex<2>(it.row());
        dual_edgeindices[2*i] = 2*i;
        dual_edgeverts[2*i] = s1.Center();
        ++it;
        if(!it) continue;
        auto&& s2 = m_mesh->template simplex<2>(it.row());
        dual_edgeindices[2*i+1] = 2*i+1;
        dual_edgeverts[2*i+1] = s2.Center();

    }






    std::cout << "Reserving" << std::endl;

    dual_faceverts.clear();
    dual_faceverts.reserve(3*m_mesh->template numSimplices<2>());
    dual_faceindices.clear();
    dual_faceindices.reserve(3*m_mesh->template numSimplices<2>());

    m_dual_vertex_form_indices.clear();
    m_dual_vertex_form_indices.reserve(m_mesh->template numSimplices<0>());

    int count=0;
    std::cout << "Writing dual face indices" << std::endl;
    for(int i=0; i < m_mesh->template simplices<0>().size(); ++i) {
        auto&& s0 = m_mesh->template simplex<0>(i);

        for(SparseMatrix::InnerIterator it1(d0, s0.Index()); it1; ++it1) {
            auto&& s1 = m_mesh->template simplex<1>(it1.row());

            SparseMatrix::InnerIterator it2(d1, s1.Index());
        if(!it2) continue;

            auto&& s2 = m_mesh->template simplex<2>(it2.row());
            dual_faceverts.push_back(s0.Center());
            if((s0[0] == s1[0]) ^ s1.isSameSign(s2)) {
            dual_faceverts.push_back(s2.Center());
            dual_faceverts.push_back(s1.Center());
            } else {
            dual_faceverts.push_back(s1.Center());
            dual_faceverts.push_back(s2.Center());
            }
            ++count;
            ++it2;
        if(!it2) continue;

            auto&& s2b = m_mesh->template simplex<2>(it2.row());
            dual_faceverts.push_back(s0.Center());
            if((s0[0] == s1[0]) ^ s1.isSameSign(s2)) {
            dual_faceverts.push_back(s1.Center());
            dual_faceverts.push_back(s2b.Center());
            } else {
            dual_faceverts.push_back(s2b.Center());
            dual_faceverts.push_back(s1.Center());
            }
            ++count;
        }
        m_dual_vertex_form_indices.push_back(count);
    }


    dual_faceindices.clear();
    dual_faceindices.resize(dual_faceverts.size());
    for(int i=0; i < dual_faceindices.size(); ++i) {
        dual_faceindices[i] = i;
    }




    std::cout << "Normalizing duals" << std::endl;

    mtao::normalizeToBBoxInPlace(dual_faceverts,m_bbox);
    mtao::normalizeToBBoxInPlace(dual_edgeverts,m_bbox);
    mtao::normalizeToBBoxInPlace(dual_vertices,m_bbox);







    //package->vertex_normals = m_mesh->getNormals();
    //package->vertex_normals = m_mesh->getNormals(NormalTriangleMesh::Area_Normal);
    package->vertex_normals = m_mesh->getNormals(NormalTriangleMesh::Angle_Normal);






















    std::cout << "Done loading mesh metadata" << std::endl;
    emit meshLoaded(package);
}
Ejemplo n.º 11
0
void
AutoStart::loadAutoStartList()
{
   TQStringList files = TDEGlobal::dirs()->findAllResources("xdgconf-autostart", "*.desktop", false, true);
   TQStringList kdefiles = TDEGlobal::dirs()->findAllResources("autostart", "*.desktop", false, true);
   files += kdefiles;
   
   for(TQStringList::ConstIterator it = files.begin();
       it != files.end();
       ++it)
   {
       KDesktopFile config(*it, true);
       if (config.hasKey("X-TDE-autostart-condition")) {
           if (!startCondition(config.readEntry("X-TDE-autostart-condition")))
              continue;
       }
       else {
           if (!startCondition(config.readEntry("X-TDE-autostart-condition")))
              continue;
       }
       if (!config.tryExec())
          continue;
       if (config.readBoolEntry("Hidden", false))
          continue;

       // Check to see if the most important ( usually ~/.config/autostart or ~/.trinity/Autostart) XDG directory
       // has overridden the Hidden directive and honor it if set to True
       bool autostartOverriddenAndDisabled = false;
       for(TQStringList::ConstIterator localit = files.begin();
           localit != files.end();
           ++localit)
       {
           if (((*localit).startsWith(TDEGlobal::dirs()->localxdgconfdir()) == true) || ((*localit).startsWith(TDEGlobal::dirs()->localtdedir()) == true)) {
               // Same local file name?
               TQString localOuter;
               TQString localInner;
               int slashPos = (*it).findRev( '/', -1, TRUE );
               if (slashPos == -1) {
                   localOuter = (*it);
               }
               else {
                   localOuter = (*it).mid(slashPos+1);
               }
               slashPos = (*localit).findRev( '/', -1, TRUE );
               if (slashPos == -1) {
                   localInner = (*localit);
               }
               else {
                   localInner = (*localit).mid(slashPos+1);
               }
               if (localOuter == localInner) {
                   // Overridden!
                   // But is Hidden == True?
                   KDesktopFile innerConfig(*localit, true);
                   if (innerConfig.readBoolEntry("Hidden", false)) {
                       // Override confirmed; exit speedily without autostarting
                       autostartOverriddenAndDisabled = true;
                   }
               }
           }
       }

       if (autostartOverriddenAndDisabled == true)
           continue;

       if (config.hasKey("OnlyShowIn"))
       {
#ifdef WITH_OLD_XDG_STD
          if ((!config.readListEntry("OnlyShowIn", ';').contains("TDE")) && (!config.readListEntry("OnlyShowIn", ';').contains("KDE")))
              continue;
#else
          if (!config.readListEntry("OnlyShowIn", ';').contains("TDE"))
              continue;
#endif
       }
       if (config.hasKey("NotShowIn"))
       {
#ifdef WITH_OLD_XDG_STD
           if ((config.readListEntry("NotShowIn", ';').contains("TDE")) || (config.readListEntry("NotShowIn", ';').contains("KDE")))
               continue;
#else
           if (config.readListEntry("NotShowIn", ';').contains("TDE"))
               continue;
#endif
       }

       AutoStartItem *item = new AutoStartItem;
       item->name = extractName(*it);
       item->service = *it;
       if (config.hasKey("X-TDE-autostart-after"))
           item->startAfter = config.readEntry("X-TDE-autostart-after");
       else
           item->startAfter = config.readEntry("X-TDE-autostart-after");
       if( m_newStartup )
       {
          if (config.hasKey("X-TDE-autostart-phase"))
              item->phase = config.readNumEntry("X-TDE-autostart-phase", 2);
          else
              item->phase = config.readNumEntry("X-TDE-autostart-phase", 2);
          if (item->phase < 0)
             item->phase = 0;
       }
       else
       {
          if (config.hasKey("X-TDE-autostart-phase"))
              item->phase = config.readNumEntry("X-TDE-autostart-phase", 1);
          else
              item->phase = config.readNumEntry("X-TDE-autostart-phase", 1);
          if (item->phase < 1)
             item->phase = 1;
       }
       m_startList->append(item);
   }

   // Check for duplicate entries and remove if found
   TQPtrListIterator<AutoStartItem> it1(*m_startList);
   TQPtrListIterator<AutoStartItem> it2(*m_startList);
   AutoStartItem *item1;
   AutoStartItem *item2;
   while ((item1 = it1.current()) != 0) {
       bool dupfound1 = false;
       it2.toFirst();
       while ((item2 = it2.current()) != 0) {
           bool dupfound2 = false;
           if (item2 != item1) {
               if (item1->service == item2->service) {
                   m_startList->removeRef(item2);
                   dupfound1 = true;
                   dupfound2 = true;
               }
           }
           if (!dupfound2) {
               ++it2;
           }
       }
       if (!dupfound1) {
           ++it1;
       }
   }
}
Ejemplo n.º 12
0
	void HACD::CreateGraph()
    {
		// vertex to triangle adjacency information
		std::vector< std::set<long> >  vertexToTriangles;		
		vertexToTriangles.resize(m_nPoints);
		for(size_t t = 0; t < m_nTriangles; ++t)
		{
			vertexToTriangles[m_triangles[t].X()].insert(static_cast<long>(t));
			vertexToTriangles[m_triangles[t].Y()].insert(static_cast<long>(t));
			vertexToTriangles[m_triangles[t].Z()].insert(static_cast<long>(t));
		}

		m_graph.Clear();
		m_graph.Allocate(m_nTriangles, 5 * m_nTriangles);
		unsigned long long tr1[3];
		unsigned long long tr2[3];
        long i1, j1, k1, i2, j2, k2;
        long t1, t2;
        for (size_t v = 0; v < m_nPoints; v++) 
		{
			std::set<long>::const_iterator it1(vertexToTriangles[v].begin()), itEnd(vertexToTriangles[v].end()); 
			for(; it1 != itEnd; ++it1)
			{
                t1 = *it1;
                i1 = m_triangles[t1].X();
                j1 = m_triangles[t1].Y();
                k1 = m_triangles[t1].Z();
				tr1[0] = GetEdgeIndex(i1, j1);
				tr1[1] = GetEdgeIndex(j1, k1);
				tr1[2] = GetEdgeIndex(k1, i1);
				std::set<long>::const_iterator it2(it1);
				for(++it2; it2 != itEnd; ++it2)
				{
                    t2 = *it2;
                    i2 = m_triangles[t2].X();
                    j2 = m_triangles[t2].Y();
                    k2 = m_triangles[t2].Z();
					tr2[0] = GetEdgeIndex(i2, j2);
					tr2[1] = GetEdgeIndex(j2, k2);
					tr2[2] = GetEdgeIndex(k2, i2);
					int shared = 0;
					for(int i = 0; i < 3; ++i)
					{
						for(int j = 0; j < 3; ++j)
						{
							if (tr1[i] == tr2[j])	
							{
								shared++;
							}
						}
					}
					if (shared == 1) // two triangles are connected if they share exactly one edge
					{
						m_graph.AddEdge(t1, t2);
					}
				}
			}
        }
        if (m_ccConnectDist >= 0.0)
        {
            m_graph.ExtractCCs();
            if (m_graph.m_nCCs > 1) 
            {
                std::vector< std::set<long> > cc2V;
                cc2V.resize(m_graph.m_nCCs);
                long cc;
                for(size_t t = 0; t < m_nTriangles; ++t)
                {
                    cc = m_graph.m_vertices[t].m_cc;
                    cc2V[cc].insert(m_triangles[t].X());
                    cc2V[cc].insert(m_triangles[t].Y());
                    cc2V[cc].insert(m_triangles[t].Z());
                }
                
                for(size_t cc1 = 0; cc1 < m_graph.m_nCCs; ++cc1)
                {
                    for(size_t cc2 = cc1+1; cc2 < m_graph.m_nCCs; ++cc2)
                    {
                        std::set<long>::const_iterator itV1(cc2V[cc1].begin()), itVEnd1(cc2V[cc1].end()); 
                        for(; itV1 != itVEnd1; ++itV1)
                        {
							double distC1C2 = std::numeric_limits<double>::max();
                            double dist;
                            t1 = -1;
                            t2 = -1;
                            std::set<long>::const_iterator itV2(cc2V[cc2].begin()), itVEnd2(cc2V[cc2].end()); 
                            for(; itV2 != itVEnd2; ++itV2)
                            {
                                dist = (m_points[*itV1] - m_points[*itV2]).GetNorm();
                                if (dist < distC1C2)
                                {
                                    distC1C2 = dist;
                                    t1 = *vertexToTriangles[*itV1].begin();
                                    
									std::set<long>::const_iterator it2(vertexToTriangles[*itV2].begin()), 
																   it2End(vertexToTriangles[*itV2].end()); 
									t2 = -1;
									for(; it2 != it2End; ++it2)
									{
										if (*it2 != t1)
										{
											t2 = *it2;
											break;
										}
									}
                                }
                            }
                            if (distC1C2 <= m_ccConnectDist && t1 > 0 && t2 > 0)
                            {
								
                                m_graph.AddEdge(t1, t2);                    
                            }
                        }
                    }
                }
            }
        }
    }
bool CTerrainShapeForSpaceTree::createTerrainShape_test(	PRootNode			*pnodeRoot,
															PDatabase			*pDatabase,
															PString				szNameFileTerrain,
															float				fScaleTerrain )
{
	PResult result;
	if(PLinkResolver::getDatabase(m_terrainDBID, szNameFileTerrain)!=PE_RESULT_NO_ERROR)
	{
		return PSSG_SET_LAST_ERROR(false,("Unable to get the default database for this sample."));
	}

	if(PSSG::Extra::resolveAllLinks()!=PE_RESULT_NO_ERROR)
	{
		return PSSG_SET_LAST_ERROR(false,("Unable to resolve all outstanding links"));
	}

	// Database File을 읽어온다.
	PDatabaseWriteLock modelWriteLock(m_terrainDBID);
	PDatabase *databaseShapeTerr = modelWriteLock.getDatabase();
	if(!databaseShapeTerr)
	{
		return PSSG_SET_LAST_ERROR(false,("Unable to lock model database"));
	}

	// Bundle Node : 즉 Model Node를 뽑아낸다.
	PListIterator modelScenes(databaseShapeTerr->getSceneList());
	PNode *pnodeRootShapeTerr = (PNode*)modelScenes.data();

	PTraversalFindNodeByType findBUndleNode(PSSG_TYPE(PBundleNode));
	findBUndleNode.traverseDepthFirst(*pnodeRootShapeTerr);
	PNode *pnodeRenderBundle = (PNode*)findBUndleNode.getFoundNode();

	if(!pnodeRenderBundle)
	{
		PTraversalFindNodeByType findRenderNode(PSSG_TYPE(PRenderNode));
		findRenderNode.traverseDepthFirst(*pnodeRootShapeTerr);
		pnodeRenderBundle = (PNode*)findRenderNode.getFoundNode();
		if(!pnodeRenderBundle)
		{
			return PSSG_SET_LAST_ERROR(false, ("Unable to find the model node because model has not rendernode."));
		}
	}

	PNode *pmodelNode_clone = (PNode*)pnodeRenderBundle->clone(pDatabase, &result);

	bool bNeedTransform = !APPROX_EQ(1.0f,fScaleTerrain);
	Matrix4	matTMforTree;
	
	if( true==bNeedTransform )
	{
		Matrix4	&mat = pmodelNode_clone->m_matrix;
		matTMforTree = matTMforTree.identity();
		float	fscaleMul = 0.0f;

		for(int i=0; i<3; ++i)
		{
			fscaleMul = mat.getElem(i,i)*fScaleTerrain;
			mat.setElem( i,i, fscaleMul );
			matTMforTree.setElem( i,i,fscaleMul );
		}
	}
 
	pnodeRoot->addChild( *pmodelNode_clone );

	PSegmentSet *segmentSet;
	PDatabaseListableIterator<PSegmentSet>		it1(*databaseShapeTerr);
	while (it1)
	{
		segmentSet = &(*it1);
		for(unsigned int i = 0 ; i < segmentSet->getSegmentCount() ; i++)
		{
			PRenderDataSource *renderdatasource = segmentSet->getSegment(i);

			if(true==bNeedTransform)
			{
				m_pContainerTri->constructAllTriangles( renderdatasource, &matTMforTree, true );
			}
			else
			{
				m_pContainerTri->constructAllTriangles( renderdatasource, NULL, true );
			}
		} 
		++it1;
	}

	m_pSpcTree->constructTree( m_pContainerTri );

	return true;
}
  mitk::Image::Pointer PartialVolumeAnalysisClusteringCalculator::CaculateAngularErrorImage(
      mitk::Image::Pointer comp1, mitk::Image::Pointer comp2, mitk::Image::Pointer probImg) const
  {

    // cast input images to itk
    typedef itk::Image<float, 3> ImageType;
    typedef mitk::ImageToItk<ImageType> CastType;
    CastType::Pointer caster = CastType::New();
    caster->SetInput(comp1);
    caster->Update();
    ImageType::Pointer comp1Image = caster->GetOutput();

    caster = CastType::New();
    caster->SetInput(comp2);
    caster->Update();
    ImageType::Pointer comp2Image = caster->GetOutput();

    caster = CastType::New();
    caster->SetInput(probImg);
    caster->Update();
    ImageType::Pointer probImage = caster->GetOutput();

    // figure out maximum probability for fiber class
    float maxProb = 0;
    itk::ImageRegionConstIterator<ImageType>
        itprob(probImage, probImage->GetLargestPossibleRegion());
    itprob.GoToBegin();
    while( !itprob.IsAtEnd() )
    {
      maxProb = itprob.Get() > maxProb ? itprob.Get() : maxProb;
      ++itprob;
    }

    // generate a list sample of angles at positions
    // where the fiber-prob is higher than .2*maxprob
    typedef float MeasurementType;
    const unsigned int MeasurementVectorLength = 2;
    typedef itk::Vector< MeasurementType , MeasurementVectorLength >
                                                                 MeasurementVectorType;
    typedef itk::Statistics::ListSample< MeasurementVectorType > ListSampleType;
    ListSampleType::Pointer listSample = ListSampleType::New();
    listSample->SetMeasurementVectorSize( MeasurementVectorLength );

    itk::ImageRegionIterator<ImageType>
        it1(comp1Image, comp1Image->GetLargestPossibleRegion());
    itk::ImageRegionIterator<ImageType>
        it2(comp2Image, comp2Image->GetLargestPossibleRegion());

    it1.GoToBegin();
    it2.GoToBegin();
    itprob.GoToBegin();

    while( !itprob.IsAtEnd() )
    {
      if(itprob.Get() > 0.2 * maxProb)
      {
        MeasurementVectorType mv;
        mv[0] = ( MeasurementType ) it1.Get();
        mv[1] = ( MeasurementType ) it2.Get();
        listSample->PushBack(mv);
      }
      ++it1;
      ++it2;
      ++itprob;
    }

    // generate a histogram from the list sample
    typedef float HistogramMeasurementType;
    typedef itk::Statistics::Histogram< HistogramMeasurementType, itk::Statistics::DenseFrequencyContainer2 > HistogramType;
    typedef itk::Statistics::SampleToHistogramFilter< ListSampleType, HistogramType > GeneratorType;
    GeneratorType::Pointer generator = GeneratorType::New();

    GeneratorType::HistogramType::SizeType size(2);
    size.Fill(30);
    generator->SetHistogramSize( size );

    generator->SetInput( listSample );
    generator->SetMarginalScale( 10.0 );

    generator->Update();

    // look for frequency mode in the histogram
    GeneratorType::HistogramType::ConstPointer histogram = generator->GetOutput();
    GeneratorType::HistogramType::ConstIterator iter = histogram->Begin();
    float maxFreq = 0;
    MeasurementVectorType maxValue;
    maxValue.Fill(0);
    while ( iter != histogram->End() )
    {
      if(iter.GetFrequency() > maxFreq)
      {
        maxFreq = iter.GetFrequency();
        maxValue[0] = iter.GetMeasurementVector()[0];
        maxValue[1] = iter.GetMeasurementVector()[1];
      }
      ++iter;
    }

    // generate return image that contains the angular
    // error of the voxels to the histogram max measurement
    ImageType::Pointer returnImage = ImageType::New();
    returnImage->SetSpacing( comp1Image->GetSpacing() );   // Set the image spacing
    returnImage->SetOrigin( comp1Image->GetOrigin() );     // Set the image origin
    returnImage->SetDirection( comp1Image->GetDirection() );  // Set the image direction
    returnImage->SetRegions( comp1Image->GetLargestPossibleRegion() );
    returnImage->Allocate();

    itk::ImageRegionConstIterator<ImageType>
        cit1(comp1Image, comp1Image->GetLargestPossibleRegion());

    itk::ImageRegionConstIterator<ImageType>
        cit2(comp2Image, comp2Image->GetLargestPossibleRegion());

    itk::ImageRegionIterator<ImageType>
        itout(returnImage, returnImage->GetLargestPossibleRegion());

    cit1.GoToBegin();
    cit2.GoToBegin();
    itout.GoToBegin();

    vnl_vector<float> v(3);
    v[0] = cos( maxValue[0] ) * sin( maxValue[1] );
    v[1] = sin( maxValue[0] ) * sin( maxValue[1] );
    v[2] = cos( maxValue[1] );
//    MITK_INFO << "max vector: " << v;
    while( !cit1.IsAtEnd() )
    {
      vnl_vector<float> v1(3);
      v1[0] = cos( cit1.Get() ) * sin( cit2.Get() );
      v1[1] = sin( cit1.Get() ) * sin( cit2.Get() );
      v1[2] = cos( cit2.Get() );

      itout.Set(fabs(angle(v,v1)));
//      MITK_INFO << "ang_error " << v1 << ": " << fabs(angle(v,v1));

      ++cit1;
      ++cit2;
      ++itout;
    }

    mitk::Image::Pointer retval = mitk::Image::New();
    retval->InitializeByItk(returnImage.GetPointer());
    retval->SetVolume(returnImage->GetBufferPointer());
    return retval;
  }
Ejemplo n.º 15
0
double StelGeodesicGridDrawer::draw(StelCore* core, int maxSearchLevel)
{
	const StelProjectorP prj = core->getProjection();
	StelPainter sPainter(prj);
	StelGeodesicGrid* geodesicGrid = core->getGeodesicGrid();

	const GeodesicSearchResult* geodesic_search_result = geodesicGrid->search(prj->unprojectViewport(), maxSearchLevel);
	
	glDisable(GL_TEXTURE_2D);
	glEnable(GL_BLEND);	
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Normal transparency mode
	core->setCurrentFrame(StelCore::FrameJ2000);	// set 2D coordinate
	sPainter.setColor(0.2,0.3,0.2);
	
	int lev = (int)(7./pow(prj->getFov(), 0.4))+2;
	if (lev>geodesicGrid->getMaxLevel()) 
		lev = geodesicGrid->getMaxLevel();

	lev = maxSearchLevel;
	Vec3d win1, win2;
	int index;
	Vec3d v0, v1, v2;
	{
		GeodesicSearchInsideIterator it1(*geodesic_search_result, lev);
		while((index = it1.next()) >= 0)
		{
			Vec3d center(0);
			geodesicGrid->getTriangleCorners(lev, index, v0, v1, v2);
			prj->project(v0, win1);
			prj->project(v1, win2);
			center += win1;
			sPainter.drawLine2d(win1[0],win1[1], win2[0],win2[1]);
			prj->project(v1, win1);
			prj->project(v2, win2);
			sPainter.drawLine2d(win1[0],win1[1], win2[0],win2[1]);
			center += win1;
			prj->project(v2, win1);
			prj->project(v0, win2);
			sPainter.drawLine2d(win1[0],win1[1], win2[0],win2[1]);
			center += win1;
			center*=0.33333;
			QString str = QString("%1 (%2)").arg(index)
			                                .arg(geodesicGrid->getPartnerTriangle(lev, index));
			glEnable(GL_TEXTURE_2D);
				prj->drawText(font,center[0]-6, center[1]+6, str);
			glDisable(GL_TEXTURE_2D);
		}
	}
	GeodesicSearchBorderIterator it1(*geodesic_search_result, lev);
	while((index = it1.next()) >= 0)
	{
		Vec3d center(0);
		geodesicGrid->getTriangleCorners(lev, index, v0, v1, v2);
		prj->project(v0, win1);
		prj->project(v1, win2);
		center += win1;
		sPainter.drawLine2d(win1[0],win1[1], win2[0],win2[1]);
		prj->project(v1, win1);
		prj->project(v2, win2);
		sPainter.drawLine2d(win1[0],win1[1], win2[0],win2[1]);
		center += win1;
		prj->project(v2, win1);
		prj->project(v0, win2);
		sPainter.drawLine2d(win1[0],win1[1], win2[0],win2[1]);
		center += win1;
		center*=0.33333;
		QString str = QString("%1 (%2)").arg(index)
		                                .arg(geodesicGrid->getPartnerTriangle(lev, index));
		glEnable(GL_TEXTURE_2D);
			prj->drawText(font,center[0]-6, center[1]+6, str);
		glDisable(GL_TEXTURE_2D);
	}
	
	return 0.;
}
Ejemplo n.º 16
0
/* Méthode qui permet de charger les texutres */
void HomeCreator3D::loadTextures()
{
    QStringList listFilter;
    listFilter << "*.jpg";
    listFilter << "*.jpeg";

    QTreeWidgetItem* txts = new QTreeWidgetItem();
    txts->setText(0, "Textures");

    QTreeWidgetItem* sols = new QTreeWidgetItem();
    sols->setText(0, "Sols");

    QTreeWidgetItem* ext = new QTreeWidgetItem();
    ext->setText(0, "Murs extérieurs");

    QTreeWidgetItem* inte = new QTreeWidgetItem();
    inte->setText(0, "Murs intérieurs");

    QDirIterator it("textures/floor", listFilter, QDir::Files | QDir::NoSymLinks);
    while (it.hasNext())
    {
        QString pathFileName = it.next();
        QString fileName = pathFileName.right(pathFileName.length()-pathFileName.lastIndexOf("/")-1);
        textures.insert(fileName, Texture(pathFileName));

        QTreeWidgetItem* item = new QTreeWidgetItem();
        item->setText(0, fileName);
        item->setIcon(0, QIcon(pathFileName));
        sols->addChild(item);
    }


    QDirIterator it1("textures/wall/exterieur", listFilter, QDir::Files | QDir::NoSymLinks);
    while (it1.hasNext())
    {
        QString pathFileName = it1.next();
        QString fileName = pathFileName.right(pathFileName.length()-pathFileName.lastIndexOf("/")-1);
        textures.insert(fileName, Texture(pathFileName));

        QTreeWidgetItem* item = new QTreeWidgetItem();
        item->setText(0, fileName);
        item->setIcon(0, QIcon(pathFileName));
        ext->addChild(item);
    }


    QDirIterator it2("textures/wall/interieur", listFilter, QDir::Files | QDir::NoSymLinks);
    while (it2.hasNext())
    {
        QString pathFileName = it2.next();
        QString fileName = pathFileName.right(pathFileName.length()-pathFileName.lastIndexOf("/")-1);
        textures.insert(fileName, Texture(pathFileName));

        QTreeWidgetItem* item = new QTreeWidgetItem();
        item->setText(0, fileName);
        item->setIcon(0, QIcon(pathFileName));
        inte->addChild(item);
    }


    txts->addChild(sols);
    txts->addChild(ext);
    txts->addChild(inte);


    window.getUi()->treeWidget->insertTopLevelItem(0, txts);
}