コード例 #1
0
ファイル: thumb_generator.cpp プロジェクト: GoBudokai/ozifi
void TThumbGeneratorImpl::DrawText(TImage& image, size_t x, size_t y, const wstring& wtext, size_t size) {
    float scale = stbtt_ScaleForPixelHeight(&Font, size);

    int w, h, xo, yo;
    unsigned char* r = image.data(0, 0, 0, 0);
    unsigned char* g = image.data(0, 0, 0, 1);
    unsigned char* b = image.data(0, 0, 0, 2);

    size_t pos = x;
    for (size_t i = 0; i < wtext.size(); i++) {
        if (iswspace(wtext[i])) {
            pos += size * 0.3;
            continue;
        }
        unsigned char* d = stbtt_GetCodepointBitmap(&Font, 0, scale, wtext[i], &w, &h, &xo, &yo);
        for (size_t wx = 0; wx < w; wx++) {
            for (size_t wy = 0; wy < h; wy++) {
                size_t cx = pos + wx + xo;
                size_t cy = y + wy + yo + size;
                if (cy >= image.height() ||
                        cx >= image.width())
                {
                    continue;
                }
                size_t dcord = image.width() * cy + cx;
                size_t scord = wy * w + wx;
                r[dcord] = d[scord];
                g[dcord] = d[scord];
                b[dcord] = d[scord];
            }
        }
        pos += w;
    }
}
コード例 #2
0
ファイル: FITS_tutorial3.C プロジェクト: adevress/root-1
// Open a FITS file and retrieve the first plane of the image array 
// as a TImage object
void FITS_tutorial3()
{
   printf("\n\n--------------------------------\n");
   printf("WELCOME TO FITS tutorial #3 !!!!\n");
   printf("--------------------------------\n");
   printf("We're gonna open a FITS file that contains several image\n");
   printf("extensions. The primary HDU contains no data.\n");
   printf("Data copyright: NASA\n\n");
   
   if (!gROOT->IsBatch()) {
      //printf("Press ENTER to start..."); getchar();
   }
   
   // Open extensions 1 to 5 from file
   //printf("Press ENTER to see a canvas with all images within the file:"); getchar();
   
   TCanvas *c = new TCanvas("c1", "FITS tutorial #1", 800, 700);
   c->Divide(2,3);
   for (int i=1; i <= 5; i++) {
      TFITSHDU *hdu = new TFITSHDU("sample3.fits", i);
      if (hdu == 0) {
         printf("ERROR: could not access the HDU\n"); return;
      }
      
      TImage *im = hdu->ReadAsImage(0);
      c->cd(i);
      im->Draw();
      delete hdu;
   }
}
コード例 #3
0
void hist_to_png_h1(TH1F * h_c, TH1F* h_e, TH1F* h_f, TString saveTitle, TString type_string)
{
  TCanvas *cPNG = new TCanvas(saveTitle,"",700,500);
  TImage *img = TImage::Create();
  char * type = type_string.Data();
  gStyle->SetOptStat(0);
  gPad->SetLogy();
  auto legend = new TLegend(0.7,0.7,0.9,0.9);
  legend->SetTextSize(0.06);
  legend->AddEntry(h_c,"CEMC","l");
  legend->AddEntry(h_e,"EEMC","l");
  legend->AddEntry(h_f,"FEMC","l");
  
  if(strcmp(type,"spatial")==0)
    {  
      h_e->GetXaxis()->SetTitle("Extrapolation distance from cluster [cm]");
      h_e->GetYaxis()->SetTitle("Counts");
    }
  h_e->Draw();
  h_c->Draw("SAME");
  h_f->Draw("SAME");
  legend->Draw();
  img->FromPad(cPNG);
  img->WriteImage(saveTitle);
}
コード例 #4
0
void draw( const TImage aImg, const double& aMaxValue, std::string aBasename) 
{
  typedef typename TImage::Domain::ConstIterator ConstIteratorOnPoints; 
  typedef typename TImage::Domain::Point Point; 
  HueShadeColorMap<double, 2> colorMap(0,aMaxValue);

  Board2D b; 
  b.setUnit ( LibBoard::Board::UCentimeter );
 
  for (ConstIteratorOnPoints it = aImg.domain().begin(), itEnd = aImg.domain().end();
       it != itEnd; ++it)
    {
      Point p = *it; 
      b << CustomStyle( p.className(), new CustomFillColor( colorMap( aImg(p) ) ) );
      b << p;
    }

  {
    std::stringstream s; 
    s << aBasename << ".eps"; 
    b.saveEPS(s.str().c_str());
  }
  #ifdef WITH_CAIRO
  {
    std::stringstream s; 
    s << aBasename << ".png"; 
    b.saveCairo(s.str().c_str(), Board2D::CairoPNG);
  }
  #endif
} 
コード例 #5
0
vtkImageData* CImageLoader::load( std::string sFilename, TImagePtr& imagePtr )
{
	cerr << "Loading data... ";
	TDataFile theData = getFileServer().loadDataSet( sFilename );
	if ( theData.first->getType() == typeid( short ) )
	{
		imagePtr = static_pointer_cast<TImage>( theData.first );
		cerr << "Correct" << endl;
	}
	else
		cerr << theData.first->getType().name() << endl;
	cerr << "done" << endl;
	cerr << "Starting conversion... ";
	// Create vtk structured points structure
  vtkImageData* sp = vtkImageData::New();
  sp->SetDimensions( theData.first->getExtent(0), theData.first->getExtent(1), theData.first->getExtent(2) );
  sp->AllocateScalars();	
  // Assign dataset to structured points
  vtkPointData *p=sp->GetPointData();
	vtkShortArray* sArray = NULL;
	vtkDoubleArray* fArray = NULL;
	TField* floatSet = dynamic_cast<TField*>( theData.first.get() );	
	if ( floatSet != NULL )
	{
		fArray = vtkDoubleArray::New();
		fArray->SetArray(floatSet->getArray(),
			theData.first->getExtent(0)*theData.first->getExtent(1)*theData.first->getExtent(2), 1 );
		p->SetScalars( fArray );
		sp->SetScalarTypeToDouble();
	}
	else 
	{
		TImage* shortSet = dynamic_cast<TImage*>( theData.first.get() );
		if ( shortSet != NULL )
		{
			short* sA = new short[theData.first->getExtent(0)*theData.first->getExtent(1)*theData.first->getExtent(2)];
			short* sAs = sA;
			for( TImage::iterator it = shortSet->begin(); it != shortSet->end(); ++it, ++sAs )
				*sAs = *it;
			sArray = vtkShortArray::New();
			sArray->SetArray( sA,
				theData.first->getExtent(0)*theData.first->getExtent(1)*theData.first->getExtent(2), 1 );
			p->SetScalars( sArray );
			sp->SetScalarTypeToShort();
		}		
		else
		{
	    sp->Delete();		
			throw( FileException( "CVTkHandler - Unknown image format in dataset. Image was not saved" ) );
		}
	}
	sp->UpdateData();
	sp->SetSpacing( 1.0, 1.0, 1.0 );
	sp->SetOrigin( static_cast<double>( theData.first->getExtent(0) )/ 2.0, 
		static_cast<double>( theData.first->getExtent(1) )/ 2.0,
		static_cast<double>( theData.first->getExtent(2) )/ 2.0	);
	cerr << sp->GetNumberOfScalarComponents() << endl;
	cerr << "done" << endl;	
	return sp;
}
コード例 #6
0
ファイル: img2pad.C プロジェクト: My-Source/root
void img2pad()
{
   // Display image in canvas and pad.
   //Author: valeriy Onuchin
   
   TImage *img = TImage::Open("rose512.jpg");
   if (!img) {
      printf("Could not create an image... exit\n");
      return;
   }
   img->SetConstRatio(kFALSE);
   img->Draw("N");

   TCanvas *c = gROOT->GetListOfCanvases()->FindObject("rose512jpg");
   c->SetFixedAspectRatio();

   TCanvas *c = new TCanvas("roses", "roses", 800, 800);
   img->Draw("T100,100,yellow");
   //img->Draw("T100,100,#556655");
   //img->Draw("T100,100");

   TImage *i1 = TImage::Open("rose512.jpg");
   i1->SetConstRatio(kFALSE);
   i1->Flip(90);
   TImage *i2 = TImage::Open("rose512.jpg");
   i2->SetConstRatio(kFALSE);
   i2->Flip(180);
   TImage *i3 = TImage::Open("rose512.jpg");
   i3->SetConstRatio(kFALSE);
   i3->Flip(270);
   TImage *i4 = TImage::Open("rose512.jpg");
   i4->SetConstRatio(kFALSE);
   i4->Mirror(kTRUE);

   float d = 0.40;
   TPad *p1 = new TPad("i1", "i1", 0.05, 0.55, 0.05+d*i1->GetWidth()/i1->GetHeight(), 0.95);
   TPad *p2 = new TPad("i2", "i2", 0.55, 0.55, 0.95, 0.55+d*i2->GetHeight()/i2->GetWidth());
   TPad *p3 = new TPad("i3", "i3", 0.55, 0.05, 0.55+d*i3->GetWidth()/i3->GetHeight(), 0.45);
   TPad *p4 = new TPad("i4", "i4", 0.05, 0.05, 0.45, 0.05+d*i4->GetHeight()/i4->GetWidth());

   p1->Draw();
   p1->cd();
   i1->Draw();
   c->cd();

   p2->Draw();
   p2->cd();
   i2->Draw();
   c->cd();

   p3->Draw();
   p3->cd();
   i3->Draw();
   c->cd();

   p4->Draw();
   p4->cd();
   i4->Draw();
   c->cd();
}
コード例 #7
0
ファイル: psview.C プロジェクト: davidlt/root
void psview()
{
   // set to batch mode -> do not display graphics
   gROOT->SetBatch(1);

   // create a PostScript file
   TString dir = gROOT->GetTutorialDir();
   dir.Append("/graphics/feynman.C");
   gROOT->Macro(dir);
   gPad->Print("feynman.eps");

   // back to graphics mode
   gROOT->SetBatch(0);

   // create an image from PS file
   TImage *ps = TImage::Open("feynman.eps");

   if (!ps) {
      printf("GhostScript (gs) program must be installed\n");
      return;
   }

   new TCanvas("psexam", "Example how to display PS file in canvas", 600, 400);
   TLatex *tex = new TLatex(0.06,0.9,"The picture below has been loaded from a PS file:");
   tex->Draw();

   TPad *eps = new TPad("eps", "eps", 0., 0., 1., 0.75);
   eps->Draw();
   eps->cd();
   ps->Draw("xxx");
}
コード例 #8
0
ファイル: SaveSpectras.C プロジェクト: RoddyMacrae/acqu-A2
void SaveOpenSpectras() {
	char *spectra_names[] =
		{"CB-Spectra",
		 "TAPS-BaF2-Spectra",
		 "TAPS-PbWO4-Spectra",
		 "TAPS-Veto-Spectra",
		 "Tagger-Spectra",
		 "EPT-Spectra",
		 "PID-Spectra",
		 "MWPC-Spectra",
		 "Scaler-Spectra", // aka trigger spectra...
		 "Livetimes-Spectra",
		 "Physics-Spectra",
		 0};

	// clean up directory...
	printf("\nDelete all PNG images on daq-master:/home/a2cb/OnlineSpectra\n");
	stringstream CmdStr;
	CmdStr << "rm /home/a2cb/acqu/OnlineSpectra/*.png";
	system(CmdStr.str().c_str());

	// prepare elog command, note the blank space at every line!
	stringstream elog_cmd;
	elog_cmd << "echo Run " << gAR->GetRunNumber() << " Online Spectra | ";
	elog_cmd << "elog -h elog.office.a2.kph -u a2online a2messung ";
	elog_cmd << "-l 'Main Group Logbook' -a Experiment='EPT test 2014-07' ";
	elog_cmd << "-a Author='PLEASE FILL IN' -a Type=Routine ";
	elog_cmd << "-a Subject='Online Spectra Run " << gAR->GetRunNumber() << "' ";
	
	// Save Spectra
	UInt_t i = 0;
	char spectra_title[50];
	char spectra_filename[100];
	
	while (spectra_names[i]){
		sprintf(spectra_title, "%s", spectra_names[i]);
		sprintf(spectra_filename, "/home/a2cb/acqu/OnlineSpectra/%02i_%s.png", i, spectra_names[i]);
		gSystem->ProcessEvents();

		if (gROOT->FindObject(spectra_title)) {

			TImage *img = TImage::Create();
			img->FromPad((TVirtualPad*)gROOT->FindObject(spectra_title));
			img->WriteImage(spectra_filename);
			delete img;
			elog_cmd << "-f " << spectra_filename << " ";
			printf("Spectra saved: %s\n", spectra_title);
		} else {
			printf("Spectra not found: %s\n", spectra_title);
		}
		i++;
	}


	printf("\nPosting all PNG images to the Elog\n");
	system(elog_cmd.str().c_str());
	printf("\nPLEASE EDIT THE ELOG ENTRY TO MAKE IT COMPLETE!\n\n");
}
コード例 #9
0
ファイル: img2pad.C プロジェクト: Y--/root
void img2pad()
{
   TImage *img = TImage::Open("$ROOTSYS/tutorials/image/rose512.jpg");
   if (!img) {
      printf("Could not create an image... exit\n");
      return;
   }
   img->SetConstRatio(kFALSE);
   img->Draw("N");

   TCanvas *c = (TCanvas *)gROOT->GetListOfCanvases()->FindObject("rose512jpg");
   c->SetFixedAspectRatio();

   TCanvas *c1 = new TCanvas("roses", "roses", 800, 800);
   img->Draw("T100,100,#ffff00");
   /*img->Draw("T100,100,#556655");*/
   /*img->Draw("T100,100");*/

   TImage *i1 = TImage::Open("$ROOTSYS/tutorials/image/rose512.jpg");
   i1->SetConstRatio(kFALSE);
   i1->Flip(90);
   TImage *i2 = TImage::Open("$ROOTSYS/tutorials/image/rose512.jpg");
   i2->SetConstRatio(kFALSE);
   i2->Flip(180);
   TImage *i3 = TImage::Open("$ROOTSYS/tutorials/image/rose512.jpg");
   i3->SetConstRatio(kFALSE);
   i3->Flip(270);
   TImage *i4 = TImage::Open("$ROOTSYS/tutorials/image/rose512.jpg");
   i4->SetConstRatio(kFALSE);
   i4->Mirror(kTRUE);

   float d = 0.40;
   TPad *p1 = new TPad("i1", "i1", 0.05, 0.55, 0.05+d*i1->GetWidth()/i1->GetHeight(), 0.95);
   TPad *p2 = new TPad("i2", "i2", 0.55, 0.55, 0.95, 0.55+d*i2->GetHeight()/i2->GetWidth());
   TPad *p3 = new TPad("i3", "i3", 0.55, 0.05, 0.55+d*i3->GetWidth()/i3->GetHeight(), 0.45);
   TPad *p4 = new TPad("i4", "i4", 0.05, 0.05, 0.45, 0.05+d*i4->GetHeight()/i4->GetWidth());

   p1->Draw();
   p1->cd();
   i1->Draw();
   c1->cd();

   p2->Draw();
   p2->cd();
   i2->Draw();
   c1->cd();

   p3->Draw();
   p3->cd();
   i3->Draw();
   c1->cd();

   p4->Draw();
   p4->cd();
   i4->Draw();
   c1->cd();
}
コード例 #10
0
void CExtractRegion::updateMask( TImage& mask, TImage& work, uint index )
{
	TImage::iterator in = work.begin();
	TImage::iterator out = mask.begin();
	while( in != work.end() )
	{
		if ( (*in) > 0 ) (*out) = index;
		++in; ++out;
	}
}
コード例 #11
0
ファイル: plot_lib.cpp プロジェクト: wutzi15/plot_lib
/**
 * \brief saves the plotted image
 * Saves the plotter image to the given filename
 * \param std::string filename - output filename for the image also determines the image type ( ".png" -> png etc.)
 * \return bool on success
 */
bool Plotter::save_image(std::string filename){
  try{
    TImage *img = TImage::Create();
    img->FromPad(canvas);
    img->WriteImage(filename.c_str());
    return true;
  }catch(std::runtime_error &e){
    std::cerr << e.what() << std::endl;
    return false;
  }
}
コード例 #12
0
ulong CExtractRegion::computeSize( TImage& region )
{
	ulong size = 0;
	TImage::iterator in = region.begin();
	while( in != region.end() )
	{
		if ( (*in) > 0 ) size++;
		++in;
	}	
	return size;
}
コード例 #13
0
ファイル: gui_common.cpp プロジェクト: pengjohn/kaixin
//添加Image控件到CoolBarList, 
// pszString必须是动态的(非Static)
// nWidth 为0 -- 自动长度
Int32 CtrlAddItemToCoolBarList_Image(TWindow*pWin,  TBarListItem* pListItem, Coord nX, Coord nY, Coord nWidth, Int32 nHeight, TBitmap * pBmp)
{
	TRectangle obBtnRec(0,0,0,0);
	Int32 nImageId = pListItem->AddCtrl(CTL_CLASS_IMAGE, 0, 0);
	TImage* pImage = static_cast<TImage*>(pWin->GetControlPtr(nImageId));

	obBtnRec.SetRect(nX, nY, nWidth, nHeight);
	pImage->SetBounds(&obBtnRec);
	pImage->SetBitmap(pBmp);
	pImage->SetEnabled(TRUE);
	return nImageId;
}
コード例 #14
0
  void FinishVertex(VertexDescriptorType target, VertexDescriptorType sourceNode)
  {
    //OutputHelpers::WriteImage(MaskImage, Helpers::GetSequentialFileName("mask", this->NumberOfFinishedVertices, "png"));
    ITKHelpers::WriteImage(MaskImage, Helpers::GetSequentialFileName("mask",
                                                                        this->NumberOfFinishedVertices, "mha"));
    //OutputHelpers::WriteVectorImageAsRGB(Image, Helpers::GetSequentialFileName("output", this->NumberOfFinishedVertices, "png"));
    ITKHelpers::WriteImage(Image, Helpers::GetSequentialFileName("output",
                                                                    this->NumberOfFinishedVertices, "mha"));

    ITKHelpers::WriteRGBImage(Image, Helpers::GetSequentialFileName("output",
                                                                    this->NumberOfFinishedVertices, "png"));

    typename TImage::PixelType holeColor;
    holeColor.SetSize(Image->GetNumberOfComponentsPerPixel());
    holeColor[0] = 255;
    holeColor[1] = 0;
    holeColor[2] = 0;

    MaskOperations::WriteMaskedRegionPNG(Image, MaskImage, Image->GetLargestPossibleRegion(), Helpers::GetSequentialFileName("maskedOutput", this->NumberOfFinishedVertices, "png"),
                       holeColor);


    typedef itk::Image<unsigned char, 2> IndicatorImageType;

    IndicatorImageType::Pointer boundaryStatusMapImage = IndicatorImageType::New();
    boundaryStatusMapImage->SetRegions(Image->GetLargestPossibleRegion());
    boundaryStatusMapImage->Allocate();
//     BoostHelpers::WritePropertyMapAsImage(BoundaryStatusMap, boundaryStatusMapImage.GetPointer(),
//                                           Helpers::GetSequentialFileName("boundaryStatusMap",
//                                           this->NumberOfFinishedVertices, "png"));

    IndicatorImageType::Pointer validBoundaryNodeImage = IndicatorImageType::New();
    validBoundaryNodeImage->SetRegions(Image->GetLargestPossibleRegion());
    validBoundaryNodeImage->Allocate();
//     BoostHelpers::WriteValidQueueNodesAsImage(BoundaryNodeQueue, BoundaryStatusMap,
//                                                 validBoundaryNodeImage.GetPointer(),
//                                           Helpers::GetSequentialFileName("boundaryQueueValidNodes",
//                                                this->NumberOfFinishedVertices, "png"));

    IndicatorImageType::Pointer allBoundaryNodeImage = IndicatorImageType::New();
    allBoundaryNodeImage->SetRegions(Image->GetLargestPossibleRegion());
    allBoundaryNodeImage->Allocate();
//     BoostHelpers::WriteAllQueueNodesAsImage(BoundaryNodeQueue, allBoundaryNodeImage.GetPointer(),
//                                           Helpers::GetSequentialFileName("boundaryQueueAllNodes",
//                                            this->NumberOfFinishedVertices, "png"));

    this->NumberOfFinishedVertices++;

    // std::cout << "Finished node " << this->NumberOfFinishedVertices << std::endl;

  }
コード例 #15
0
ファイル: thumb_generator.cpp プロジェクト: GoBudokai/ozifi
// store image inside png
void SaveImage(const TImage& image, const string& destFile) {
    vector<unsigned char> result(image.width() * image.height() * 4);
    unsigned char* d;
    const unsigned char* r = image.data(0, 0, 0, 0);
    const unsigned char* g = image.data(0, 0, 0, 1);
    const unsigned char* b = image.data(0, 0, 0, 2);
    int sp = image.spectrum();
    if (sp == 4) {
        const unsigned char* a = image.data(0, 0, 0, 3);
        for (d = result.data(); d < result.data() + result.size();) {
            *(d++) = *(r++);
            *(d++) = *(g++);
            *(d++) = *(b++);
            *(d++) = *(a++);
        }
    } else if (sp == 3) {
        for (d = result.data(); d < result.data() + result.size();) {
            *(d++) = *(r++);
            *(d++) = *(g++);
            *(d++) = *(b++);
            *(d++) = 255;
        }
    } else {
        throw UException("failed to save image - wrong type");
    }
    size_t err = lodepng::encode(destFile, result, image.width(), image.height());
    if (err) {
        throw UException(lodepng_error_text(err));
    }
}
コード例 #16
0
ファイル: pad2png.C プロジェクト: MycrofD/root
void pad2png()
{
   TCanvas *c = new TCanvas;
   TH1F *h = new TH1F("gaus", "gaus", 100, -5, 5);
   h->FillRandom("gaus", 10000);
   h->Draw();

   gSystem->ProcessEvents();

   TImage *img = TImage::Create();

   img->FromPad(c);

   img->WriteImage("canvas.png");
}
コード例 #17
0
  void paint_vertex(VertexDescriptorType target, VertexDescriptorType source, TGraph& g) const
  {
    itk::Index<2> target_index;
    target_index[0] = target[0];
    target_index[1] = target[1];

    itk::Index<2> source_index;
    source_index[0] = source[0];
    source_index[1] = source[1];

    assert(image->GetLargestPossibleRegion().IsInside(source_index));
    assert(image->GetLargestPossibleRegion().IsInside(target_index));

    Image->SetPixel(target_index, Image->GetPixel(source_index));
  }
コード例 #18
0
ファイル: Subtract.cpp プロジェクト: JanKolomaznik/MedV4D
void
Subtract( TImage &aImage1, TImage &aImage2 )
{
	if ( aImage1.GetSize() != aImage2.GetSize() ) {
		_THROW_ ErrorHandling::EBadParameter(":hl:");
	}
	typename TImage::Iterator it1 = aImage1.GetIterator();
	typename TImage::Iterator it2 = aImage2.GetIterator();

	while ( it1 != it1.End() &&  it2 != it2.End() ) {
		*it1 = Abs(*it1 - *it2);
		++it1;
		++it2;
	}
}
コード例 #19
0
void 
computerBasicNormalsFromHeightField(const TImage &anHeightMap, TImageVector &vectorField)
{
  for(typename TImage::Domain::ConstIterator it = anHeightMap.domain().begin(); 
      it != anHeightMap.domain().end(); it++){
    if(anHeightMap.domain().isInside(*it+Z2i::Point::diagonal(1))&&
       anHeightMap.domain().isInside(*it-Z2i::Point::diagonal(1))){
      double dx = (anHeightMap(*it-Z2i::Point(1,0))-anHeightMap(*it+Z2i::Point(1,0)))/2.0;
      double dy = (anHeightMap(*it-Z2i::Point(0,1))-anHeightMap(*it+Z2i::Point(0,1)))/2.0;
      Z3i::RealPoint n (dx, dy, 1);
      n /= n.norm();
      vectorField.setValue(*it,n);
    }
  }
}
コード例 #20
0
void hist_to_png(TH2F * h, TString saveTitle, TString type_string)
{
  TCanvas *cPNG = new TCanvas(saveTitle,"",700,500);
  TImage *img = TImage::Create();
  char * type = type_string.Data();
  gPad->SetLogz();
  gStyle->SetOptStat(0);
  if(strcmp(type,"phi")==0)
    {
      h->GetXaxis()->SetTitle("Track Phi");
      h->GetYaxis()->SetTitle("Cluster Phi");
    }
  else if(strcmp(type,"eta")==0)
    {
      h->GetXaxis()->SetTitle("Track Eta");
      h->GetYaxis()->SetTitle("Cluster Eta"); 
    }
  else if(strcmp(type,"theta")==0)
    {
      h->GetXaxis()->SetTitle("Track Theta");
      h->GetYaxis()->SetTitle("Cluster Theta");
    }
  else if(strcmp(type,"mom")==0)
    {
      h->GetXaxis()->SetTitle("Track Momentum [GeV]");
      h->GetYaxis()->SetTitle("Cluster Momentum [GeV]");
    }
  else if(strcmp(type,"posx")==0)
    {
      h->GetXaxis()->SetTitle("Track Position X [cm]");
      h->GetYaxis()->SetTitle("Cluster Position X [cm]");
    }
  else if(strcmp(type,"posy")==0)
    {
      h->GetXaxis()->SetTitle("Track Position Y [cm]");
      h->GetYaxis()->SetTitle("Cluster Position Y [cm]");
    }
  else if(strcmp(type,"posz")==0)
    {  
      h->GetXaxis()->SetTitle("Track Position Z [cm]");
      h->GetYaxis()->SetTitle("Cluster Position Z [cm]");
    }
  h->Draw("colz9");
  img->FromPad(cPNG);
  img->WriteImage(saveTitle);

  delete img;
}
コード例 #21
0
static QImage 
getImage(const TImage &anImage, double gridSize=1.0 ){
  typedef ConstImageAdapter<TImage, typename TImage::Domain, 
                            functors::BasicDomainSubSampler<typename TImage::Domain, int, double>,  
                            typename TImage::Value,
                            functors::Identity > ConstImageAdapterForSubSampling;
  
  std::vector<double> scales;
  scales.push_back(gridSize);
  scales.push_back(gridSize);
  
  functors::BasicDomainSubSampler<typename TImage::Domain, int, double> subSampler (anImage.domain(), scales, Z2i::Point(0,0)); 
  typename TImage::Domain newDomain = subSampler.getSubSampledDomain();
  functors::Identity id;
  ConstImageAdapterForSubSampling  scaledImage (anImage, newDomain, subSampler, id ); 
  
  unsigned int height = scaledImage.domain().upperBound()[1]+1;
  unsigned int width = scaledImage.domain().upperBound()[0]+1;
  uchar * data = new uchar [height*width*4];
  for(unsigned int i=0; i<height; i++){
    for(unsigned int j=0; j<width; j++){
      data[(j+width*i)*4]=scaledImage(Z2i::Point(j,i));
      data[(j+width*i)*4+1]=scaledImage(Z2i::Point(j,i));
      data[(j+width*i)*4+2]=scaledImage(Z2i::Point(j,i));
      data[(j+width*i)*4+3]=scaledImage(Z2i::Point(j,i));
    }
  }
   QImage result(  data, width,  height, QImage::Format_RGB32 );
   return result;
}
コード例 #22
0
ファイル: glWnd.cpp プロジェクト: tnextday/HappyShake
bool loadAnyTexture(CMzString &filename, Texture* tex )
{
	TImage img;
	char strTexPath[_MAX_PATH];
	wcstombs(strTexPath, filename.C_Str(), _MAX_PATH);
	bool ret = false;

	if(img.LoadFromFile(strTexPath))
	{
		img.Bind2DTexture(tex->tex);
		ret = true;
	}
	tex->w = img.GetWidth() ;
	tex->h = img.GetHeight();
	return ret;
}
コード例 #23
0
    /// Constructor to build item representing file name cell.
    TFileAttachmentItem(const QFileInfo& fileInfo, TFileAttachmentWidget* owner) :
      AAttachmentItem(fileInfo.fileName().toStdString().c_str(), owner, nullptr),
      FileInfo(fileInfo), 
      _contactCardData(nullptr)
      {
      owner->TotalAttachmentSize += fileInfo.size();

      QString path = fileInfo.absoluteFilePath();
      TImage image;
      
      image.load(path);
      if (image.isNull())
        setToolTip(path);
      else
        setToolTip(image.toHtml() );
      }
コード例 #24
0
/**
 * 显示连接的动画
 *
 * \param pApp
 * \param nStep 	连接第几步
 */
void TInitForm::_DrawDot(TApplication * pApp, int nStep)
{

	for(int i=0; i<LOADING_FORM_DOT_NUM; i++)
	{
		TImage* pTImage = NULL;
		pTImage = static_cast< TImage* >(this->GetControlPtr(nDotID[i]));
		if(pTImage!= NULL)
		{
			if(i<=nStep)
				pTImage->SetBitmapByResId (APP_KA_ID_BITMAP_Loading_dot_hl);
			else
				pTImage->SetBitmapByResId (APP_KA_ID_BITMAP_Loading_dot);
		}
	}	
	return;
}
コード例 #25
0
ファイル: glWnd.cpp プロジェクト: tnextday/HappyShake
bool CglWnd::setImageFromDC( HDC dc, int width /*= 480*/, int height /*= 720*/ )
{
	TImage img;
	CMzString strAppPath(_MAX_PATH);
	char strFilePath[_MAX_PATH];
	GetWorkPath(strAppPath.C_Str(), strAppPath.GetBufferSize());
	strAppPath += L"\\Data\\Last.jpg";
	wcstombs(strFilePath, strAppPath.C_Str(), _MAX_PATH);
	if (img.LoadFromDC(dc, 0, 0, width, height))
	{
		img.Bind2DTexture(texture[TEXID_BG]);
		img.SaveJPEG(strFilePath);
		m_imageFileName = strAppPath;
		return true;
	}
	return false;
}
コード例 #26
0
    adError LoadBitmap(const TString& fileName, adBitmapPtr pBitmap)
    {
        if(pBitmap == NULL)
            return AD_ERROR_INVALID_POINTER;

        if(pBitmap->width == 0 || pBitmap->height == 0 || pBitmap->stride == 0 || 
            pBitmap->format <= AD_PIXEL_FORMAT_NONE || pBitmap->format >= AD_PIXEL_FORMAT_SIZE || 
            pBitmap->data == NULL)
            return AD_ERROR_INVALID_BITMAP;

        if(!IsFileExists(fileName.c_str()))
            return AD_ERROR_FILE_IS_NOT_EXIST;

        adError result = AD_ERROR_UNKNOWN;

        HGLOBAL hGlobal = LoadFileToMemory(fileName.c_str());
        if(hGlobal)
        {
            TImage *pImage = TImage::Load(hGlobal);
            if(pImage)
            {
                TView::Format format = TView::None;
                switch(pBitmap->format)
                {
                case AD_PIXEL_FORMAT_ARGB32:
                    format = TView::Bgra32;
                    break;
                }
                if(format)
                {
                    TView view(pBitmap->width, pBitmap->height, pBitmap->stride, format, pBitmap->data);
                    Simd::ResizeBilinear(*pImage->View(), view);
                    result = AD_OK;
                }
                delete pImage;
            }
            else
                result = AD_ERROR_CANT_LOAD_IMAGE;
            ::GlobalFree(hGlobal);
        }
        else
            result = AD_ERROR_CANT_OPEN_FILE;

        return result;
    }
コード例 #27
0
ファイル: itkLabelSampler.cpp プロジェクト: junaidnaseer/MITK
void LabelSampler< TImage>
::GenerateData()
{


  srand (time(nullptr));
  this->AllocateOutputs();

  typename TImage::ConstPointer input = this->GetInput();
  TImage * output = this->GetOutput();

  m_NumberOfSampledVoxels = 0;

  ImageRegionConstIterator<TImage> inputIter(input, input->GetLargestPossibleRegion());
  ImageRegionIterator<TImage> outputIter(output, output->GetLargestPossibleRegion());
  while (!inputIter.IsAtEnd())
  {
    if (inputIter.Get() > 0)
    {

      if(m_LabelVoxelCountMap.find(inputIter.Get()) == m_LabelVoxelCountMap.end())
        m_LabelVoxelCountMap[inputIter.Get()] = 0;
      m_LabelVoxelCountMap[inputIter.Get()]++;

      double r;
      if(inputIter.Get() == m_Label || m_Label == -1 ){
        r = (double)(rand()) / RAND_MAX;
        if (r < m_AcceptRate)
        {
          outputIter.Set(inputIter.Get());
          m_NumberOfSampledVoxels++;
        }
      }else
        outputIter.Set(0);

    }
    else
    {
      outputIter.Set(0);
    }
    ++inputIter;
    ++outputIter;
  }

}
コード例 #28
0
Boolean TInitForm::_OnWinInitEvent(TApplication * pApp, EventType * pEvent)
{
	for(int i=0; i<LOADING_FORM_DOT_NUM; i++)
	{
		TImage* pTImage = new TImage;
		if(pTImage->Create(this))
		{
			TRectangle obBtnRec(DOT_X+((SCR_W - DOT_X*2)/LOADING_FORM_DOT_NUM)*i, DOT_Y, DOT_W, DOT_H);
			nDotID[i] = pTImage->GetId();//save button ID
			pTImage->SetBounds(&obBtnRec); 	
			pTImage->SetBitmapByResId (APP_KA_ID_BITMAP_Loading_dot); 
		}
	}

	_DrawDot(pApp, nLoadStep);
	m_nTimerId = TIMER_Create(1000, TIMER_MODE_AUTORUN | TIMER_MODE_PERIOD, NULL, 0, 0);	
	return TRUE;
}
コード例 #29
0
ファイル: tmvaglob.C プロジェクト: CeF3TB/BTFAnalysis
   void plot_logo( Float_t v_scale = 1.0, Float_t skew = 1.0 )
   {

      TImage *img = findImage("tmva_logo.gif");
      if (!img) {
         cout << "+++ Could not open image tmva_logo.gif" << endl;
         return;
      }
      
      img->SetConstRatio(kFALSE);
      UInt_t h_ = img->GetHeight();
      UInt_t w_ = img->GetWidth();

      Float_t r = w_/h_;
      gPad->Update();
      Float_t rpad = Double_t(gPad->VtoAbsPixel(0) - gPad->VtoAbsPixel(1))/(gPad->UtoAbsPixel(1) - gPad->UtoAbsPixel(0));
      r *= rpad;

      Float_t d = 0.055;
      // absolute coordinates
      Float_t x1R = 1 - gStyle->GetPadRightMargin(); 
      Float_t y1B = 1 - gStyle->GetPadTopMargin()+.01; // we like the logo to sit a bit above the histo 

      Float_t x1L = x1R - d*r/skew;
      Float_t y1T = y1B + d*v_scale*skew;
      if (y1T>0.99) y1T = 0.99;

      TPad *p1 = new TPad("imgpad", "imgpad", x1L, y1B, x1R, y1T );
      p1->SetRightMargin(0);
      p1->SetBottomMargin(0);
      p1->SetLeftMargin(0);
      p1->SetTopMargin(0);
      p1->Draw();

      Int_t xSizeInPixel = p1->UtoAbsPixel(1) - p1->UtoAbsPixel(0);
      Int_t ySizeInPixel = p1->VtoAbsPixel(0) - p1->VtoAbsPixel(1);
      if (xSizeInPixel<=25 || ySizeInPixel<=25) {
         delete p1;
         return; // ROOT doesn't draw smaller than this
      }

      p1->cd();
      img->Draw();
   } 
  void initialize_vertex(VertexDescriptorType v, TGraph& g) const
  {
    //std::cout << "Initializing " << v[0] << " " << v[1] << std::endl;
    // Create the patch object and associate with the node
    itk::Index<2> index;
    index[0] = v[0];
    index[1] = v[1];

    itk::ImageRegion<2> region = ITKHelpers::GetRegionInRadiusAroundPixel(index, HalfWidth);

    unsigned int numberOfValues = Image->GetNumberOfComponentsPerPixel() * region.GetNumberOfPixels();
    if(MaskImage->IsValid(region))
      {
      std::vector<float> pixels(numberOfValues, 0);
      itk::ImageRegionIterator<TImage> imageIterator(Image, region);
 
      unsigned int pixelCounter = 0;
      while(!imageIterator.IsAtEnd())
        {
        TImage::PixelType p = imageIterator.Get();
        for(unsigned int component = 0; component < p.Size(); ++component)
          {
          pixels[Image->GetNumberOfComponentsPerPixel() * pixelCounter + component] = p[component];
          }
        pixelCounter++;
        ++imageIterator;
        }
      FeatureVectorPixelDescriptor descriptor(this->image, this->mask, region);
      descriptor.SetVertex(v);
      put(DescriptorMap, v, descriptor);
      }
    else
      {
      FeatureVectorPixelDescriptor descriptor(numberOfValues);
      descriptor.SetVertex(v);
      put(DescriptorMap, v, descriptor);
      }

  };