コード例 #1
0
ファイル: wtd_lg.cpp プロジェクト: JumperWang/farsight-clone
/**	@brief main routinue for 3D watershed
*/
short 
wtd_lg::wtd3d(std::vector<pix_t*>& pix, short h_min, short h_max, short step_size)
{
	mCitType cit(mImgpFilt,mImgpFilt->GetLargestPossibleRegion());
	mItType it(mImgpLabel,mImgpLabel->GetLargestPossibleRegion());
	mItType it2(mImgpLabel,mImgpLabel->GetLargestPossibleRegion());

	short current_label = 0; //minimum label ???
	unsigned char current_dist;
	pix_t* fictitious_pix = new pix_t();

	//sorting
	std::sort( pix.begin(), pix.end(),compare(mImgpFilt,mImageSize));

	int size = (int)pix.size();

	//store the neighbors of a pixel
	std::vector<pix_t*> nbs;

	//queue structure
	std::deque<pix_t*> q;

	int start_i=0, end_i=0;		
	miIndex[0] = pix[end_i]->x_;
	miIndex[1] = pix[end_i]->y_;
	miIndex[2] = pix[end_i]->z_;
	cit.SetIndex(miIndex);
	for( short h=h_min; h<=h_max; h+=step_size )
	{
		start_i = end_i;

		for(;end_i<size && cit.Get()<=h;end_i++)
		//while(end_i<size && cit.Get()<=h )
		{	
			//end_i++;
			miIndex[0] = pix[end_i]->x_;
			miIndex[1] = pix[end_i]->y_;
			miIndex[2] = pix[end_i]->z_;
			cit.SetIndex(miIndex);
		}

		for( int i=start_i;i<end_i;i++ )
		{
			miIndex[0] = pix[i]->x_;
			miIndex[1] = pix[i]->y_;
			miIndex[2] = pix[i]->z_;
			it.SetIndex(miIndex);
			it.Set(MASK);
			get_neighbors(pix[i], nbs );
			bool flag=false;
			for(unsigned int j=0;j<nbs.size();++j )
			{
				miIndex[0] = nbs[j]->x_;
				miIndex[1] = nbs[j]->y_;
				miIndex[2] = nbs[j]->z_;
				it.SetIndex(miIndex);
				if( it.Get()>0 || it.Get() == WSHED )
				{
					flag=true;
					break;
				}
			}
			if(flag)
			{
				mvDist[ id_image( pix[i]->x_ , pix[i]->y_ , pix[i]->z_ ) ] = 1;
				q.push_back( pix[i] );
			}
		}
		current_dist = 1;
		q.push_back( fictitious_pix );
		while( true )
		{
			pix_t* p = q.front();
			q.pop_front();
			if( p->z_ == -1 )
			{
				if( q.empty() ) break;
				else
				{
					q.push_back( fictitious_pix );
					current_dist++;
					p = q.front();
					q.pop_front();
				}
			}

			get_neighbors(p, nbs );
			for(unsigned int i=0;i<nbs.size();++i )
			{
				miIndex[0] = nbs[i]->x_;
				miIndex[1] = nbs[i]->y_;
				miIndex[2] = nbs[i]->z_;
				it.SetIndex(miIndex);

				if( mvDist[ id_image( nbs[i]->x_ , nbs[i]->y_ , nbs[i]->z_ ) ]<current_dist && ( it.Get()>0 
					|| it.Get()==WSHED ) )
				{
					miIndex[0] = p->x_;
					miIndex[1] = p->y_;
					miIndex[2] = p->z_;
					it2.SetIndex(miIndex);
					if( it.Get()>0 )
					{
						if( it2.Get()==MASK || it2.Get() == WSHED )
						{

							it2.Set( it.Get() );
						}
						else if( it2.Get() != it.Get() )
						{
							it2.Set(WSHED);
						}
					}
					else if( it2.Get() == MASK )
						it2.Set( WSHED );
				}
				else if( it.Get()==MASK && mvDist[ id_image( nbs[i]->x_ , nbs[i]->y_ , nbs[i]->z_ ) ] == 0 )
				{
					mvDist[ id_image( nbs[i]->x_ , nbs[i]->y_ , nbs[i]->z_ ) ] = current_dist+1;
					q.push_back( nbs[i] );
				}
			}
		}

		for( int i=start_i;i<end_i;i++ )
		{
			mvDist[ id_image( pix[i]->x_ , pix[i]->y_ , pix[i]->z_ ) ] = 0;
			miIndex[0] = pix[i]->x_;
			miIndex[1] = pix[i]->y_;
			miIndex[2] = pix[i]->z_;
			it.SetIndex(miIndex);
			if( it.Get() == MASK )
			{
				current_label++;
				q.push_back( pix[i] );
				it.Set(current_label);
				while( !q.empty() )
				{
					pix_t* p1 = q.front();
					q.pop_front();
					get_neighbors(p1, nbs );
					for(unsigned int j=0;j<nbs.size();++j )
					{
						miIndex[0] = nbs[j]->x_;
						miIndex[1] = nbs[j]->y_;
						miIndex[2] = nbs[j]->z_;
						it2.SetIndex(miIndex);
						if( it2.Get() == MASK )
						{
							q.push_back( nbs[j] );
							it2.Set( current_label );
						}
					}
				}

			}
		}
	}

	//remove wtd
	remove_wtd(pix);

	//release memory
	delete fictitious_pix;
	nbs.clear();
	q.clear();

	return current_label;
}
void FiniteDiffOdfMaximaExtractionFilter< PixelType, ShOrder, NrOdfDirections>
::AfterThreadedGenerateData()
{
    MITK_INFO << "Generating vector field";
    vtkSmartPointer<vtkCellArray> m_VtkCellArray = vtkSmartPointer<vtkCellArray>::New();
    vtkSmartPointer<vtkPoints>    m_VtkPoints = vtkSmartPointer<vtkPoints>::New();

    typename CoefficientImageType::Pointer ShCoeffImage = static_cast< CoefficientImageType* >( this->ProcessObject::GetInput(0) );
    ImageRegionConstIterator< CoefficientImageType > cit(ShCoeffImage, ShCoeffImage->GetLargestPossibleRegion() );

    mitk::Vector3D spacing = ShCoeffImage->GetSpacing();
    double minSpacing = spacing[0];
    if (spacing[1]<minSpacing)
        minSpacing = spacing[1];
    if (spacing[2]<minSpacing)
        minSpacing = spacing[2];

    int maxProgress = ShCoeffImage->GetLargestPossibleRegion().GetSize()[0]*ShCoeffImage->GetLargestPossibleRegion().GetSize()[1]*ShCoeffImage->GetLargestPossibleRegion().GetSize()[2];
    boost::progress_display disp(maxProgress);

    while( !cit.IsAtEnd() )
    {
        ++disp;

        typename CoefficientImageType::IndexType index = cit.GetIndex();
        if (m_MaskImage->GetPixel(index)==0)
        {
            ++cit;
            continue;
        }

        for (unsigned int i=0; i<m_DirectionImageContainer->Size(); i++)
        {
            ItkDirectionImage::Pointer img = m_DirectionImageContainer->GetElement(i);
            itk::Vector< float, 3 > pixel = img->GetPixel(index);
            DirectionType dir; dir[0] = pixel[0]; dir[1] = pixel[1]; dir[2] = pixel[2];

            vtkSmartPointer<vtkPolyLine> container = vtkSmartPointer<vtkPolyLine>::New();
            itk::ContinuousIndex<double, 3> center;
            center[0] = index[0];
            center[1] = index[1];
            center[2] = index[2];
            itk::Point<double> worldCenter;
            m_MaskImage->TransformContinuousIndexToPhysicalPoint( center, worldCenter );

            itk::Point<double> worldStart;
            worldStart[0] = worldCenter[0]-dir[0]/2 * minSpacing;
            worldStart[1] = worldCenter[1]-dir[1]/2 * minSpacing;
            worldStart[2] = worldCenter[2]-dir[2]/2 * minSpacing;
            vtkIdType id = m_VtkPoints->InsertNextPoint(worldStart.GetDataPointer());
            container->GetPointIds()->InsertNextId(id);
            itk::Point<double> worldEnd;
            worldEnd[0] = worldCenter[0]+dir[0]/2 * minSpacing;
            worldEnd[1] = worldCenter[1]+dir[1]/2 * minSpacing;
            worldEnd[2] = worldCenter[2]+dir[2]/2 * minSpacing;
            id = m_VtkPoints->InsertNextPoint(worldEnd.GetDataPointer());
            container->GetPointIds()->InsertNextId(id);
            m_VtkCellArray->InsertNextCell(container);
        }
        ++cit;
    }

    vtkSmartPointer<vtkPolyData> directionsPolyData = vtkSmartPointer<vtkPolyData>::New();
    directionsPolyData->SetPoints(m_VtkPoints);
    directionsPolyData->SetLines(m_VtkCellArray);
    m_OutputFiberBundle = mitk::FiberBundle::New(directionsPolyData);

    for (unsigned int i=0; i<m_DirectionImageContainer->Size(); i++)
    {
        ItkDirectionImage::Pointer img = m_DirectionImageContainer->GetElement(i);
        this->SetNthOutput(i, img);
    }
}
void FiniteDiffOdfMaximaExtractionFilter< PixelType, ShOrder, NrOdfDirections>
::ThreadedGenerateData( const OutputImageRegionType& outputRegionForThread, ThreadIdType threadID )
{
    typename CoefficientImageType::Pointer ShCoeffImage = static_cast< CoefficientImageType* >( this->ProcessObject::GetInput(0) );

    ImageRegionConstIterator< CoefficientImageType > cit(ShCoeffImage, outputRegionForThread );

    OdfType odf;
    while( !cit.IsAtEnd() )
    {
        typename CoefficientImageType::IndexType index = cit.GetIndex();
        if (m_MaskImage->GetPixel(index)==0)
        {
            ++cit;
            continue;
        }

        CoefficientPixelType c = cit.Get();

        // calculate ODF
        double max = 0;
        odf.Fill(0.0);
        for (int i=0; i<NrOdfDirections; i++)
        {
            for (int j=0; j<m_NumCoeffs; j++)
                odf[i] += c[j]*m_ShBasis(i,j);
            if (odf[i]>max)
                max = odf[i];
        }
        if (max<0.0001)
        {
            ++cit;
            continue;
        }

        std::vector< DirectionType > candidates, peaks, temp;
        peaks.clear();
        max *= m_PeakThreshold;                         // relative threshold
        FindCandidatePeaks(odf, max, candidates);       // find all local maxima
        candidates = MeanShiftClustering(candidates);   // cluster maxima

        vnl_matrix< double > shBasis, sphCoords;
        Cart2Sph(candidates, sphCoords);                // convert candidate peaks to spherical angles
        shBasis = CalcShBasis(sphCoords);            // evaluate spherical harmonics at each peak
        max = 0.0;
        for (unsigned int i=0; i<candidates.size(); i++)         // scale peaks according to ODF value
        {
            double val = 0;
            for (int j=0; j<m_NumCoeffs; j++)
                val += c[j]*shBasis(i,j);
            if (val>max)
                max = val;
            peaks.push_back(candidates[i]*val);
        }
        std::sort( peaks.begin(), peaks.end(), CompareVectors );  // sort peaks

        // kick out directions to close to a larger direction (too far away to cluster but too close to keep)
        unsigned int m = peaks.size();
        if ( m>m_DirectionImageContainer->Size() )
            m = m_DirectionImageContainer->Size();
        for (unsigned int i=0; i<m; i++)
        {
            DirectionType v1 = peaks.at(i);
            double val = v1.magnitude();
            if (val<max*m_PeakThreshold || val<m_AbsolutePeakThreshold)
                break;

            bool flag = true;
            for (unsigned int j=0; j<peaks.size(); j++)
                if (i!=j)
                {
                    DirectionType v2 = peaks.at(j);
                    double val2 = v2.magnitude();
                    double angle = fabs(dot_product(v1,v2)/(val*val2));
                    if (angle>m_AngularThreshold && val<val2)
                    {
                        flag = false;
                        break;
                    }
                }

            if (flag)
                temp.push_back(v1);
        }
        peaks = temp;

        // fill output image
        unsigned int num = peaks.size();
        if ( num>m_DirectionImageContainer->Size() )
            num = m_DirectionImageContainer->Size();
        for (unsigned int i=0; i<num; i++)
        {
            vnl_vector<double> dir = peaks.at(i);

            ItkDirectionImage::Pointer img = m_DirectionImageContainer->GetElement(i);

            switch (m_NormalizationMethod)
            {
            case NO_NORM:
                break;
            case SINGLE_VEC_NORM:
                dir.normalize();
                break;
            case MAX_VEC_NORM:
                dir /= max;
                break;
            }

            dir = m_MaskImage->GetDirection()*dir;
            itk::Vector< float, 3 > pixel;
            pixel.SetElement(0, -dir[0]);
            pixel.SetElement(1, dir[1]);
            pixel.SetElement(2, dir[2]);
            img->SetPixel(index, pixel);
        }
        m_NumDirectionsImage->SetPixel(index, num);
        ++cit;
    }
    MITK_INFO << "Thread " << threadID << " finished extraction";
}
コード例 #4
0
ファイル: reportwindow.cpp プロジェクト: Wushaowei001/xtuple
QDomDocument ReportWindow::document() {
    QDomDocument doc = QDomDocument("openRPTDef");
    QDomElement root = doc.createElement("report");
    doc.appendChild(root);

    //title
    QDomElement title = doc.createElement("title");
    title.appendChild(doc.createTextNode(reportTitle()));
    root.appendChild(title);

    QDomElement rname = doc.createElement("name");
    rname.appendChild(doc.createTextNode(reportName()));
    root.appendChild(rname);

    QDomElement rdesc = doc.createElement("description");
    rdesc.appendChild(doc.createTextNode(reportDescription()));
    root.appendChild(rdesc);

    for(QMap<QString,ORParameter>::iterator it = _definedParams.begin();
            it != _definedParams.end(); it++) {
        QDomElement param = doc.createElement("parameter");
        ORParameter paramData = it.data();
        param.setAttribute("name", paramData.name);
        param.setAttribute("type", paramData.type);
        param.setAttribute("default", paramData.defaultValue);
        param.setAttribute("active", (paramData.active ? "true" : "false") );
        if(paramData.listtype.isEmpty())
          param.appendChild(doc.createTextNode(paramData.description));
        else
        {
          param.setAttribute("listtype", paramData.listtype);

          QDomElement paramDesc = doc.createElement("description");
          paramDesc.appendChild(doc.createTextNode(paramData.description));
          param.appendChild(paramDesc);

          if(paramData.listtype == "dynamic")
          {
            QDomElement paramQuery = doc.createElement("query");
            paramQuery.appendChild(doc.createTextNode(paramData.query));
            param.appendChild(paramQuery);
          }

          if(paramData.listtype == "static")
          {
            for(QList<QPair<QString,QString> >::iterator sit = paramData.values.begin();
                  sit != paramData.values.end(); sit++) {
              QDomElement paramItem = doc.createElement("item");
              paramItem.setAttribute("value", (*sit).first);
              paramItem.appendChild(doc.createTextNode((*sit).second));
              param.appendChild(paramItem);
            }
          }
        }
        root.appendChild(param);
    }

    if((watermarkUseStaticText() && !watermarkText().isEmpty()) || 
        (!watermarkUseStaticText() && !watermarkQuery().isEmpty() && !watermarkColumn().isEmpty())) {
        QDomElement wm = doc.createElement("watermark");
        if(watermarkUseStaticText()) {
            QDomElement wmtext = doc.createElement("text");
            wmtext.appendChild(doc.createTextNode(watermarkText()));
            wm.appendChild(wmtext);
        } else {
            QDomElement wmdata = doc.createElement("data");
            QDomElement wmdq = doc.createElement("query");
            wmdq.appendChild(doc.createTextNode(watermarkQuery()));
            wmdata.appendChild(wmdq);
            QDomElement wmdc = doc.createElement("column");
            wmdc.appendChild(doc.createTextNode(watermarkColumn()));
            wmdata.appendChild(wmdc);
            wm.appendChild(wmdata);
        }
        if(!watermarkUseDefaultFont()) {
            ReportEntity::buildXMLFont(doc,wm,watermarkFont());
        }
        QDomElement wmopac = doc.createElement("opacity");
        wmopac.appendChild(doc.createTextNode(QString::number(watermarkOpacity())));
        wm.appendChild(wmopac);
        root.appendChild(wm);
    }

    if(bgEnabled()) {
        QDomElement bg = doc.createElement("background");
        if(bgStatic()) {
            QDomElement bgimg = doc.createElement("image");
            bgimg.appendChild(doc.createTextNode(bgImage()));
            bg.appendChild(bgimg);
        } else {
            QDomElement bgdata = doc.createElement("data");
            QDomElement bgdq = doc.createElement("query");
            bgdq.appendChild(doc.createTextNode(bgQuery()));
            bgdata.appendChild(bgdq);
            QDomElement bgdc = doc.createElement("column");
            bgdc.appendChild(doc.createTextNode(bgColumn()));
            bgdata.appendChild(bgdc);
            bg.appendChild(bgdata);
        }
        QDomElement bgmode = doc.createElement("mode");
        bgmode.appendChild(doc.createTextNode(bgResizeMode()));
        bg.appendChild(bgmode);
        QDomElement bgopac = doc.createElement("opacity");
        bgopac.appendChild(doc.createTextNode(QString::number(bgOpacity())));
        bg.appendChild(bgopac);

        QDomElement bgrect = doc.createElement("rect");
        QDomElement bgrectx = doc.createElement("x");
        bgrectx.appendChild(doc.createTextNode(QString::number(bgBoundsX())));
        bgrect.appendChild(bgrectx);
        QDomElement bgrecty = doc.createElement("y");
        bgrecty.appendChild(doc.createTextNode(QString::number(bgBoundsY())));
        bgrect.appendChild(bgrecty);
        QDomElement bgrectw = doc.createElement("width");
        bgrectw.appendChild(doc.createTextNode(QString::number(bgBoundsWidth())));
        bgrect.appendChild(bgrectw);
        QDomElement bgrecth = doc.createElement("height");
        bgrecth.appendChild(doc.createTextNode(QString::number(bgBoundsHeight())));
        bgrect.appendChild(bgrecth);
        bg.appendChild(bgrect);

        int align = bgAlign();
        // horizontal
        if((align & Qt::AlignRight) == Qt::AlignRight)
            bg.appendChild(doc.createElement("right"));
        else if((align & Qt::AlignHCenter) == Qt::AlignHCenter)
            bg.appendChild(doc.createElement("hcenter"));
        else // Qt::AlignLeft
            bg.appendChild(doc.createElement("left"));
        // vertical
        if((align & Qt::AlignBottom) == Qt::AlignBottom)
            bg.appendChild(doc.createElement("bottom"));
        else if((align & Qt::AlignVCenter) == Qt::AlignVCenter)
            bg.appendChild(doc.createElement("vcenter"));
        else // Qt::AlignTop
            bg.appendChild(doc.createElement("top"));

        root.appendChild(bg);
    }

    // pageOptions
    // -- size
    QDomElement size = doc.createElement("size");
    if(pageOptions->getPageSize() == "Custom") {
        QDomElement page_width = doc.createElement("width");
        page_width.appendChild(doc.createTextNode(QString::number((int)(pageOptions->getCustomWidth()*100))));
        size.appendChild(page_width);
        QDomElement page_height = doc.createElement("height");
        page_height.appendChild(doc.createTextNode(QString::number((int)(pageOptions->getCustomHeight()*100))));
        size.appendChild(page_height);
    } else if(pageOptions->getPageSize() == "Labels") {
        size.appendChild(doc.createTextNode("Labels"));
        QDomElement labeltype = doc.createElement("labeltype");
        labeltype.appendChild(doc.createTextNode(pageOptions->getLabelType()));
        root.appendChild(labeltype);
    } else {
        size.appendChild(doc.createTextNode(pageOptions->getPageSize()));
    }
    root.appendChild(size);
    // -- orientation
    QString str_orientation;
    if(pageOptions->isPortrait()) {
        str_orientation = "portrait";
    } else {
        str_orientation = "landscape";
    }
    root.appendChild(doc.createElement(str_orientation));
    // -- margins
    QDomElement margin;
    margin = doc.createElement("topmargin");
    margin.appendChild(doc.createTextNode(QString::number((int)(pageOptions->getMarginTop()*100))));
    root.appendChild(margin);
    margin = doc.createElement("bottommargin");
    margin.appendChild(doc.createTextNode(QString::number((int)(pageOptions->getMarginBottom()*100))));
    root.appendChild(margin);
    margin = doc.createElement("rightmargin");
    margin.appendChild(doc.createTextNode(QString::number((int)(pageOptions->getMarginRight()*100))));
    root.appendChild(margin);
    margin = doc.createElement("leftmargin");
    margin.appendChild(doc.createTextNode(QString::number((int)(pageOptions->getMarginLeft()*100))));
    root.appendChild(margin);

    // write out are Query Sources
    QDomElement qsource;
    QDomElement qname;
    QDomElement qsql;
    QuerySource * qs = NULL;
    for(unsigned int i = 0; i < qsList->size(); i++) {
        qs = qsList->get(i);
        qsource = doc.createElement("querysource");
        qname = doc.createElement("name");
        qname.appendChild(doc.createTextNode(qs->name()));
        qsource.appendChild(qname);
        qsql = doc.createElement("sql");
        qsql.appendChild(doc.createTextNode(qs->query()));
        qsource.appendChild(qsql);
        root.appendChild(qsource);
    }
    qs = NULL;

    QDomElement cdef;
    QDomElement cname;
    QDomElement ccomponent;
    QMapIterator<QString, QColor> cit(_colorMap);
    while(cit.hasNext())
    {
        cit.next();
        cdef = doc.createElement("colordef");
        cname = doc.createElement("name");
        cname.appendChild(doc.createTextNode(cit.key()));
        cdef.appendChild(cname);
        ccomponent = doc.createElement("red");
        ccomponent.appendChild(doc.createTextNode(QString::number(cit.value().red())));
        cdef.appendChild(ccomponent);
        ccomponent = doc.createElement("green");
        ccomponent.appendChild(doc.createTextNode(QString::number(cit.value().green())));
        cdef.appendChild(ccomponent);
        ccomponent = doc.createElement("blue");
        ccomponent.appendChild(doc.createTextNode(QString::number(cit.value().blue())));
        cdef.appendChild(ccomponent);
        root.appendChild(cdef);
    }

    QDomElement section;

    // report head
    if(rptHead) {
        section = doc.createElement("rpthead");
        rptHead->buildXML(doc, section);
        root.appendChild(section);
    }

    // page head first
    if(pageHeadFirst) {
        section = doc.createElement("pghead");
        section.appendChild(doc.createElement("firstpage"));
        pageHeadFirst->buildXML(doc, section);
        root.appendChild(section);
    }
    // page head odd
    if(pageHeadOdd) {
        section = doc.createElement("pghead");
        section.appendChild(doc.createElement("odd"));
        pageHeadOdd->buildXML(doc, section);
        root.appendChild(section);
    }
    // page head even
    if(pageHeadEven) {
        section = doc.createElement("pghead");
        section.appendChild(doc.createElement("even"));
        pageHeadEven->buildXML(doc, section);
        root.appendChild(section);
    }
    // page head last
    if(pageHeadLast) {
        section = doc.createElement("pghead");
        section.appendChild(doc.createElement("lastpage"));
        pageHeadLast->buildXML(doc, section);
        root.appendChild(section);
    }
    // page head any
    if(pageHeadAny) {
        section = doc.createElement("pghead");
        pageHeadAny->buildXML(doc, section);
        root.appendChild(section);
    }

    // detail sections
    for(int ii = 0; ii < detailSectionCount(); ii++) {
        section = doc.createElement("section");
        getSection(ii)->buildXML(doc,section);
        root.appendChild(section);
    }

    // page foot first
    if(pageFootFirst) {
        section = doc.createElement("pgfoot");
        section.appendChild(doc.createElement("firstpage"));
        pageFootFirst->buildXML(doc, section);
        root.appendChild(section);
    }
    // page foot odd
    if(pageFootOdd) {
        section = doc.createElement("pgfoot");
        section.appendChild(doc.createElement("odd"));
        pageFootOdd->buildXML(doc, section);
        root.appendChild(section);
    }
    // page foot even
    if(pageFootEven) {
        section = doc.createElement("pgfoot");
        section.appendChild(doc.createElement("even"));
        pageFootEven->buildXML(doc, section);
        root.appendChild(section);
    }
    // page foot last
    if(pageFootLast) {
        section = doc.createElement("pgfoot");
        section.appendChild(doc.createElement("lastpage"));
        pageFootLast->buildXML(doc, section);
        root.appendChild(section);
    }
    // page foot any
    if(pageFootAny) {
        section = doc.createElement("pgfoot");
        pageFootAny->buildXML(doc, section);
        root.appendChild(section);
    }

    // report foot
    if(rptFoot) {
        section = doc.createElement("rptfoot");
        rptFoot->buildXML(doc, section);
        root.appendChild(section);
    }

    return doc;
}
コード例 #5
0
ファイル: heapInspection.cpp プロジェクト: ericbbcc/hotspot
void HeapInspection::heap_inspection(outputStream* st, bool need_prologue) {
  ResourceMark rm;
  HeapWord* ref;

  CollectedHeap* heap = Universe::heap();
  bool is_shared_heap = false;
  switch (heap->kind()) {
    case CollectedHeap::G1CollectedHeap:
    case CollectedHeap::GenCollectedHeap: {
      is_shared_heap = true;
      SharedHeap* sh = (SharedHeap*)heap;
      if (need_prologue) {
        sh->gc_prologue(false /* !full */); // get any necessary locks, etc.
      }
      ref = sh->perm_gen()->used_region().start();
      break;
    }
#ifndef SERIALGC
    case CollectedHeap::ParallelScavengeHeap: {
      ParallelScavengeHeap* psh = (ParallelScavengeHeap*)heap;
      ref = psh->perm_gen()->object_space()->used_region().start();
      break;
    }
#endif // SERIALGC
    default:
      ShouldNotReachHere(); // Unexpected heap kind for this op
  }
  // Collect klass instance info
  KlassInfoTable cit(KlassInfoTable::cit_size, ref);
  if (!cit.allocation_failed()) {
    // Iterate over objects in the heap
    RecordInstanceClosure ric(&cit);
    // If this operation encounters a bad object when using CMS,
    // consider using safe_object_iterate() which avoids perm gen
    // objects that may contain bad references.
    Universe::heap()->object_iterate(&ric);

    // Report if certain classes are not counted because of
    // running out of C-heap for the histogram.
    size_t missed_count = ric.missed_count();
    if (missed_count != 0) {
      st->print_cr("WARNING: Ran out of C-heap; undercounted " SIZE_FORMAT
                   " total instances in data below",
                   missed_count);
    }
    // Sort and print klass instance info
    KlassInfoHisto histo("\n"
                     " num     #instances         #bytes  class name\n"
                     "----------------------------------------------",
                     KlassInfoHisto::histo_initial_size);
    HistoClosure hc(&histo);
    cit.iterate(&hc);
    histo.sort();
    histo.print_on(st);
  } else {
    st->print_cr("WARNING: Ran out of C-heap; histogram not generated");
  }
  st->flush();

  if (need_prologue && is_shared_heap) {
    SharedHeap* sh = (SharedHeap*)heap;
    sh->gc_epilogue(false /* !full */); // release all acquired locks, etc.
  }
}
コード例 #6
0
void import_multichannel_exr( const boost::filesystem::path& p, bool relative, bool sequence)
{
    bool tiled;

    if(!Imf::isOpenExrFile( filesystem::file_cstring( p), tiled))
    {
        app().error( "Can't open EXR file");
        return;
    }

    Imf::InputFile ifile( filesystem::file_cstring( p));
    const Imf::ChannelList& ch_list( ifile.header().channels());

    std::set<std::string> channel_set;
    for( Imf::ChannelList::ConstIterator it( ch_list.begin()); it != ch_list.end(); ++it)
        channel_set.insert( std::string( it.name()));

    if( channel_set.empty())
    {
        app().error( "EXR file has no channels");
        return;
    }

    app().document().composition().deselect_all();
    std::auto_ptr<undo::add_nodes_command_t> command( new undo::add_nodes_command_t());

    image::input_node_t *node = new image::input_node_t( p, sequence, app().document().composition().composition_dir());
    node->set_composition( &app().document().composition());
    node->create_params();
    node->select( true);
    app().ui()->main_window()->composition_view().place_node( node);

    const int node_spacing = 120;

    Imath::V2f loc( node->location());
    loc.x += node_spacing;

    std::set<std::string> layer_set;
    ch_list.layers( layer_set);

    for( std::set<std::string>::iterator sit( layer_set.begin()); sit != layer_set.end(); ++sit)
    {
        Imf::ChannelList::ConstIterator it, last;
        ch_list.channelsInLayer( *sit, it, last);

        std::auto_ptr<node_t> node_copy( new_clone( *node));
        node->set_location( loc);
        loc.x += node_spacing;
        import_layer( node_copy.get(), it, last, channel_set);
        command->add_node( node_copy);
    }

    std::vector<std::string> channels;

    // handle color layer
    if( channel_set.count( "R") || channel_set.count( "B") || channel_set.count( "B"))
    {
        channels.push_back( "A");
        channels.push_back( "B");
        channels.push_back( "G");
        channels.push_back( "R");

        std::auto_ptr<node_t> node_copy( new_clone( *node));
        node->set_location( loc);
        loc.x += node_spacing;
        import_layer( node_copy.get(), channels, channel_set);
        command->add_node( node_copy);
    }

    if( channel_set.count( "Y") || channel_set.count( "RY") || channel_set.count( "BY"))
    {
        channels.push_back( "A");
        channels.push_back( "BY");
        channels.push_back( "RY");
        channels.push_back( "Y");

        std::auto_ptr<node_t> node_copy( new_clone( *node));
        node->set_location( loc);
        loc.x += node_spacing;
        import_layer( node_copy.get(), channels, channel_set);
        command->add_node( node_copy);
    }

    if( !channel_set.empty())
    {
        for( std::set<std::string>::iterator cit( channel_set.begin()); cit != channel_set.end(); ++cit)
        {
            channels.push_back( *cit);

            if( channels.size() == 4)
            {
                std::auto_ptr<node_t> node_copy( new_clone( *node));
                node->set_location( loc);
                loc.x += node_spacing;
                import_layer( node_copy.get(), channels, channel_set);
                command->add_node( node_copy);
            }
        }

        if( !channels.empty())
        {
            std::auto_ptr<node_t> node_copy( new_clone( *node));
            node->set_location( loc);
            loc.x += node_spacing;
            import_layer( node_copy.get(), channels, channel_set);
            command->add_node( node_copy);
        }
    }

    command->redo();
    app().document().undo_stack().push_back( command);
    app().document().composition().selection_changed();
    app().ui()->update();
    delete node;
}
コード例 #7
0
ContainerIterator Container::end()
{
	ContainerIterator cit(this);
	return cit;
}
コード例 #8
0
ファイル: doru1.cpp プロジェクト: andrei14vl/infooltenia-1
int main(){
cit();
rezolva();
return 0;
}
コード例 #9
0
BL_ArmatureConstraint* BL_ArmatureObject::GetConstraint(int index)
{
	SG_DList::iterator<BL_ArmatureConstraint> cit(m_controlledConstraints);
	for (cit.begin(); !cit.end() && index; ++cit, --index);
	return (cit.end()) ? NULL : *cit;
}
コード例 #10
0
int TaskForceClass::DoCombat (void)
{
    int combat;
    SetCombatTime(TheCampaign.CurrentTime);

#if 0 // JPO mthis stuff now done in Choose Target - like Battalion
    // KCK: Super simple targetting (c)
    Team				who = GetTeam();
    CampEntity			e;
    FalconEntity		*react_against=NULL,*air_react_against=NULL;
    int					react,spot,best_reaction=1,best_air_react=1;
    int					search_dist;
    float				react_distance,air_react_distance,d;
    react_distance = air_react_distance = 9999.0F;

    SetEngaged(0);
    SetCombat(0);
    SetChecked();

    search_dist = GetDetectionRange(Air);
#ifdef VU_GRID_TREE_Y_MAJOR
    VuGridIterator detit(RealUnitProxList,YPos(),XPos(),(BIG_SCALAR)GridToSim(search_dist));
#else
    VuGridIterator detit(RealUnitProxList,XPos(),YPos(),(BIG_SCALAR)GridToSim(search_dist));
#endif
    e = (CampEntity)detit.GetFirst();
    while (e)
    {
        if (GetRoE(who,e->GetTeam(),ROE_GROUND_FIRE) == ROE_ALLOWED)
        {
            combat = 0;
            react = DetectVs(e,&d,&combat,&spot);
            if (!e->IsFlight() && react >= best_reaction && d < react_distance)
            {
                // React vs a ground/Naval target
                best_reaction = react;
                react_distance = d;
                react_against = e;
                SetEngaged(1);
                SetCombat(combat);
            }
            else if (e->IsFlight() && react >= best_air_react && d < air_react_distance)
            {
                // React vs an air target -
                best_air_react = react;
                air_react_distance = d;
                air_react_against = e;
                if (!e->IsAggregate())
                {
                    // Pick a specific aircraft in the flight if it's deaggregated
                    CampEnterCriticalSection();
                    if (e->GetComponents())
                    {
                        VuListIterator	cit(e->GetComponents());
                        FalconEntity	*fe;
                        float			rsq,brsq=FLT_MAX;

                        fe = (FalconEntity *)cit.GetFirst();
                        while (fe)
                        {
                            rsq = DistSqu(XPos(),YPos(),fe->XPos(),fe->YPos());
                            if (rsq < brsq)
                            {
                                air_react_against = fe;
                                air_react_distance = (float)sqrt(rsq);
                                brsq = rsq;
                            }
                            fe = (FalconEntity *)cit.GetNext();
                        }
                    }
                    CampLeaveCriticalSection();
                }
                SetEngaged(1);
                SetCombat(combat);
            }
        }
        e = (CampEntity)detit.GetNext();
    }

    if (air_react_against)
        SetAirTarget(air_react_against);
    if (react_against)
        SetTarget(react_against);
#endif
    if (Engaged())
    {
        FalconEntity	*e = GetTarget();
        FalconEntity	*a = GetAirTarget();

        // Check vs our Ground Target
        if (!e)
            SetTarget(NULL);
        else
        {
            if (Combat() && IsAggregate())
            {
                combat = ::DoCombat(this,e);
                if (combat <= 0 || Targeted())
                    SetTargeted(0);
            }
        }
        // Check vs our Air Target
        if (!a)
            SetAirTarget(NULL);
        else if (Combat() && IsAggregate())
        {
            combat = ::DoCombat(this,a);
            if (combat < 0)
                SetAirTarget(NULL);							// Clear targeting data so we can look for another
        }
    }

    return 0;
}
コード例 #11
0
int TaskForceClass::ChooseTarget (void)
{
    FalconEntity	*artTarget,*react_against=NULL,*air_react_against=NULL;
    CampEntity		e;
    float		d,react_distance,air_react_distance;
    int			react,best_reaction=1,best_air_react=1,combat,retval=0,pass=0,spot=0,estr=0,capture=0,nomove=0;
    int			search_dist;
    Team		who;

    if (IsChecked())
        return Engaged();

    who = GetTeam();
    react_distance = air_react_distance = 9999.0F;

#ifdef DEBUG
    DWORD				timec = GetTickCount();
#endif

    // Special case for fire support
    if (Targeted())
        artTarget = GetTarget();					// Save our target
    else
        artTarget = NULL;

    SetEngaged(0);
    SetCombat(0);
    SetChecked();

    search_dist = GetDetectionRange(Air);
    if (search_dist < MAX_GROUND_SEARCH)
        search_dist = MAX_GROUND_SEARCH;
#ifdef VU_GRID_TREE_Y_MAJOR
    VuGridIterator detit(RealUnitProxList,YPos(),XPos(),(BIG_SCALAR)GridToSim(search_dist));
#else
    VuGridIterator detit(RealUnitProxList,XPos(),YPos(),(BIG_SCALAR)GridToSim(search_dist));
#endif
    //  CalculateSOJ(detit); 2002-02-19 REMOVED BY S.G. eFalcon 1.10 SOJ code removed

    e = (CampEntity)detit.GetFirst();
    while (e)
    {
        if (GetRoE(who,e->GetTeam(),ROE_GROUND_FIRE) == ROE_ALLOWED)
        {
            combat = 0;
            react = DetectVs(e,&d,&combat,&spot);
            if (!e->IsFlight() && react >= best_reaction && d < react_distance)
            {
                // React vs a ground/Naval target
                best_reaction = react;
                react_distance = d;
                react_against = e;
                SetEngaged(1);
                SetCombat(combat);
            }
            else if (e->IsFlight() && react >= best_air_react && d < air_react_distance)
            {
                // React vs an air target -
                best_air_react = react;
                air_react_distance = d;
                air_react_against = e;
                if (!e->IsAggregate())
                {
                    // Pick a specific aircraft in the flight if it's deaggregated
                    CampEnterCriticalSection();
                    if (e->GetComponents())
                    {
                        VuListIterator	cit(e->GetComponents());
                        FalconEntity	*fe;
                        float			rsq,brsq=FLT_MAX;

                        fe = (FalconEntity *)cit.GetFirst();
                        while (fe)
                        {
                            rsq = DistSqu(XPos(),YPos(),fe->XPos(),fe->YPos());
                            if (rsq < brsq)
                            {
                                air_react_against = fe;
                                air_react_distance = (float)sqrt(rsq);
                                brsq = rsq;
                            }
                            fe = (FalconEntity *)cit.GetNext();
                        }
                    }
                    CampLeaveCriticalSection();
                }
                // Make sure our radar is on (if we have one)
                if (!IsEmitting() && class_data->RadarVehicle < 255 && GetNumVehicles(class_data->RadarVehicle))
                    SetEmitting(1);
                SetEngaged(1);
                SetCombat(combat);
            }
        }
        e = (CampEntity)detit.GetNext();
    }
    SetOdds ((GetTotalVehicles() * 10) / (estr+10));

    if (!Parent() && best_reaction > 1)
        EngageParent(this,react_against);

    if (air_react_against)
    {
        SetAirTarget(air_react_against);
        retval = 1;
    }
    if (react_against)
    {
        SetTarget(react_against);
        SetTargeted(0);
        retval = 1;
    }
    else if (artTarget && (!artTarget->IsUnit() || ((Unit)artTarget)->Engaged()) && orders == GORD_SUPPORT)
    {
        // Keep blowing away this target until the target gets out of range, disengages, or we get new orders
        // (Target will get reset after a null DoCombat result)
        SetTarget(artTarget);
        SetTargeted(1);
        SetEngaged(1);
        SetCombat(1);
        return -1;			// We want to sit here and shoot until we can't any longer
    }
    if (nomove)
        return -1;
    return retval;
}
コード例 #12
0
bool CppEditorCompletion::doObjectCompletion( const QString &objName )
{
    if ( !ths )
	return FALSE;
    QString object( objName );
    int i = -1;
    if ( ( i = object.findRev( "->" ) ) != -1 )
	object = object.mid( i + 2 );
    if ( ( i = object.findRev( "." ) ) != -1 )
	object = object.mid( i + 1 );
    object = object.simplifyWhiteSpace();
    QObject *obj = 0;
    if ( ths->name() == object || object == "this" ) {
	obj = ths;
    } else {
	obj = ths->child( object );
    }

    if ( !obj )
	return FALSE;

    QValueList<CompletionEntry> lst;

    if ( obj->children() ) {
	for ( QObjectListIt cit( *obj->children() ); cit.current(); ++cit ) {
	    QString s( cit.current()->name() );
	    if ( s.find( " " ) == -1 && s.find( "qt_" ) == -1 && s.find( "unnamed" ) == -1 ) {
		CompletionEntry c;
		c.type = "variable";
		c.text = s;
		c.prefix = "";
		lst << c;
	    }
	}
    }

    QStrList props = obj->metaObject()->propertyNames( TRUE );
    for ( QPtrListIterator<char> pit( props ); pit.current(); ++pit ) {
	QString f( pit.current() );
	QChar c = f[ 0 ];
	f.remove( (uint)0, 1 );
	f.prepend( c.upper() );
	f.prepend( "set" );

	CompletionEntry ce;
	ce.type = "property";
	ce.text = f;
	ce.postfix = "()";

	if ( lst.find( ce ) == lst.end() )
	    lst << ce;
    }

    QStrList slts = obj->metaObject()->slotNames( TRUE );
    for ( QPtrListIterator<char> sit( slts ); sit.current(); ++sit ) {
	QString f( sit.current() );
	f = f.left( f.find( "(" ) );
	CompletionEntry c;
	c.type = "slot";
	c.text = f;
	c.postfix = "()";
	if ( lst.find( c ) == lst.end() )
	    lst << c;
    }

    if ( lst.isEmpty() )
	return FALSE;

    showCompletion( lst );
    return TRUE;
}