コード例 #1
0
int Mesh::NewColor(int a, int b, Scalar c)
{
	Vector &A = GetColor(a);
	Vector &B = GetColor(b);

	return AddColor(A*c + B*(1-c));
}
コード例 #2
0
ファイル: AnnotWriter.cpp プロジェクト: Akujiism/BePDF
void AnnotWriter::DoAnnotation(Annotation* a) {
	AddRect(&mAnnot, "Rect", a->GetRect());
	if (a->HasColor()) {
		AddColor(&mAnnot, "C", a->GetColor());
	}
	if (a->GetDate()[0] != 0) {
		AddString(&mAnnot, "M", (char*)a->GetDate());
	}
	AddInteger(&mAnnot, "F", a->GetFlags()->Flags());
	if (a->GetTitle() != NULL) {
		AddString(&mAnnot, "T", a->GetTitle());
	}
	if (a->GetOpacity() != 1.0) {
		AddReal(&mAnnot, "CA", a->GetOpacity());
	}
	PopupAnnot* popup = a->GetPopup();
	if (popup != NULL) {
		popup->SetParentRef(a->GetRef());
		if (is_empty_ref(popup->GetRef())) {
			popup->SetRef(mXRefTable.GetNewRef(xrefEntryUncompressed));
		}
		AddRef(&mAnnot, "Popup", popup->GetRef());
	}
	if (HasAppearanceStream(a)) {
		mASRef = mXRefTable.GetNewRef(xrefEntryUncompressed);
		Object ap;
		ap.initDict(mXRef);
		AddRef(&ap, "N", mASRef);
		AddDict(&mAnnot, "AP", &ap);
	}
	if (dynamic_cast<PopupAnnot*>(a) == NULL) {
		AddRef(&mAnnot, "P", mPageRef);
	}
}
コード例 #3
0
ファイル: ConfigFile.cpp プロジェクト: 373137461/OBS
void ConfigFile::SetColorList(CTSTR lpSection, CTSTR lpKey, List<Color4> &ColorList)
{
    while(HasKey(lpSection, lpKey))
        Remove(lpSection, lpKey);

    for(unsigned int i=0; i<ColorList.Num(); i++)
        AddColor(lpSection, lpKey, ColorList[i]);
}
コード例 #4
0
void AnimaMappedValues::SetColor(const AnimaString& propertyName, AnimaColorGenerator* value)
{
	AnimaString pName = _uniqueName + propertyName;
	if (_colorsMap.find(pName) == _colorsMap.end())
		AddColor(propertyName, value);
	else
		_colorsMap[pName] = value;
}
コード例 #5
0
	void ColorListEditorWidget::on_AddColorButton__released ()
	{
		QColorDialog dia (this);
		if (dia.exec () != QDialog::Accepted)
			return;

		AddColor (dia.selectedColor ());
	}
コード例 #6
0
	void ColorListEditorWidget::reject ()
	{
		Model_->clear ();
		const auto& var = XmlSettingsManager::Instance ()
				.property ("OverrideColorsList");
		const auto& colors = var.value<QList<QColor>> ();
		for (const auto& color : colors)
			AddColor (color);
	}
コード例 #7
0
ファイル: PS_Color.cpp プロジェクト: jjayne/nSIGHTS
void MviewColorSetup()
{
    int nextColor = 0;

    // system colors
    AddColor(::GetSysColor(COLOR_MENU),     sc_Background, nextColor);
    AddColor(::GetSysColor(COLOR_BTNFACE),  sc_Foreground, nextColor);

    // defined colors
    AddColor(RGB(255,   0,      0),         sc_Red, nextColor);
    AddColor(RGB(0,     255,    0),         sc_Green, nextColor);
    AddColor(RGB(0,     0,      255),       sc_Blue, nextColor);
    AddColor(RGB(0,     255,    255),       sc_Yellow, nextColor);
    AddColor(RGB(0,     0,      0),         sc_Black, nextColor);
    AddColor(RGB(255,   255,    255),       sc_White, nextColor);
    AddColor(RGB(0,     0,      64),        sc_LightBlue, nextColor);
    AddColor(RGB(64,    0,      0),         sc_Pink, nextColor);
}
コード例 #8
0
// constructor
Gradient::Gradient(bool empty)
#ifdef ICON_O_MATIC
	: BArchivable(),
	  Observable(),
	  Transformable(),
#else
	: Transformable(),
#endif

	  fColors(4),
	  fType(GRADIENT_LINEAR),
	  fInterpolation(INTERPOLATION_SMOOTH),
	  fInheritTransformation(true)
{
	if (!empty) {
		AddColor(BGradient::ColorStop(0, 0, 0, 255, 0.0), 0);
		AddColor(BGradient::ColorStop(255, 255, 255, 255, 1.0), 1);
	}
}
コード例 #9
0
ファイル: ColorMap.cpp プロジェクト: Luomu/pioneer
void ColorMap::Generate(Graphics::Renderer *r, const Color &a, const Color &b, const Color &c)
{
	std::vector<Uint8> colors;
	const int w = 4;
	AddColor(w, Color(255, 255, 255), colors);
	AddColor(w, a, colors);
	AddColor(w, b, colors);
	AddColor(w, c, colors);
	vector2f size(colors.size()/3, 1.f);

	const Graphics::TextureFormat format = Graphics::TEXTURE_RGB_888;

	if (!m_texture.Valid()) {
		const Graphics::TextureSampleMode sampleMode = m_smooth ? Graphics::LINEAR_CLAMP : Graphics::NEAREST_CLAMP;
		m_texture.Reset(r->CreateTexture(Graphics::TextureDescriptor(Graphics::TEXTURE_RGB_888, size, sampleMode)));
	}

	m_texture->Update(&colors[0], size, format);
}
コード例 #10
0
void AnimaMappedValues::SetColor(const AnimaString& propertyName, AnimaColor4f value)
{
	AnimaString pName = _uniqueName + propertyName + ".valueGenerator";
	AnimaColorGenerator* generator = (AnimaColorGenerator*)_dataGeneratorManager->GetGenerator(pName);
	if (generator == nullptr)
		AddColor(propertyName, value);
	else
	{
		generator->SetColor(value);
		//SetColor(propertyName, generator);
	}
}
コード例 #11
0
// SetColors
void
Gradient::SetColors(const Gradient& other)
{
#ifdef ICON_O_MATIC
	AutoNotificationSuspender _(this);
#endif

	_MakeEmpty();
	for (int32 i = 0; BGradient::ColorStop* step = other.ColorAt(i); i++)
		AddColor(*step, i);

	Notify();
}
コード例 #12
0
// constructor
Gradient::Gradient(const Gradient& other)
#ifdef ICON_O_MATIC
	: BArchivable(other),
	  Observable(),
	  Transformable(other),
#else
	: Transformable(other),
#endif

	  fColors(4),
	  fType(other.fType),
	  fInterpolation(other.fInterpolation),
	  fInheritTransformation(other.fInheritTransformation)
{
	for (int32 i = 0; BGradient::ColorStop* step = other.ColorAt(i); i++) {
		AddColor(*step, i);
	}
}
コード例 #13
0
// constructor
Gradient::Gradient(BMessage* archive)
#ifdef ICON_O_MATIC
	: BArchivable(archive),
	  Observable(),
	  Transformable(),
#else
	: Transformable(),
#endif

	  fColors(4),
	  fType(GRADIENT_LINEAR),
	  fInterpolation(INTERPOLATION_SMOOTH),
	  fInheritTransformation(true)
{
	if (!archive)
		return;

	// read transformation
	int32 size = Transformable::matrix_size;
	const void* matrix;
	ssize_t dataSize = size * sizeof(double);
	if (archive->FindData("transformation", B_DOUBLE_TYPE,
						  &matrix, &dataSize) == B_OK
		&& dataSize == (ssize_t)(size * sizeof(double)))
		LoadFrom((const double*)matrix);

	// color steps
	BGradient::ColorStop step;
	for (int32 i = 0; archive->FindFloat("offset", i, &step.offset) >= B_OK; i++) {
		if (archive->FindInt32("color", i, (int32*)&step.color) >= B_OK)
			AddColor(step, i);
		else
			break;
	}
	if (archive->FindInt32("type", (int32*)&fType) < B_OK)
		fType = GRADIENT_LINEAR;

	if (archive->FindInt32("interpolation", (int32*)&fInterpolation) < B_OK)
		fInterpolation = INTERPOLATION_SMOOTH;

	if (archive->FindBool("inherit transformation",
						  &fInheritTransformation) < B_OK)
		fInheritTransformation = true;
}
コード例 #14
0
void AnimaMappedValues::AddColor(const AnimaString& propertyName, AnimaColor4f value)
{
	AnimaString pName = _uniqueName + propertyName + ".valueGenerator";
	AnimaColorGenerator* generator = _dataGeneratorManager->CreateColorGenerator(pName);

	if (generator == nullptr)
	{
		int i = 1;

		AnimaString suffix = FormatString(".valueGenerator.%d", i);
		while (generator == nullptr)
		{
			generator = _dataGeneratorManager->CreateColorGenerator(pName + suffix);

			i++;
			suffix = FormatString(".valueGenerator.%d", i);
		}
	}

	generator->SetGeneratedFromMappedValues(true);
	generator->SetColor(value);

	AddColor(propertyName, generator);
}
コード例 #15
0
ファイル: Colors.cpp プロジェクト: Zeatherann/zombiesquares
void ColorsInit() {
#define AddColor(color,name) Colors[name]=color;ColorsInv[color]=name
    AddColor(sf::Color(0  ,0  ,0  ,0  ),ct_invalid);
    AddColor(sf::Color(255,128,0  ,255),ct_player);
    AddColor(sf::Color(255,0  ,0  ,255),ct_zombie);
    AddColor(sf::Color(128,255,255,255),ct_slowzombie);
    AddColor(sf::Color(255,0  ,255,255),ct_fastzombie);
    AddColor(sf::Color(0  ,255,255,255),ct_lazer);
    AddColor(sf::Color(0  ,0  ,128,255),ct_wall);
    AddColor(sf::Color(0  ,0  ,0  ,255),ct_floor);
    AddColor(sf::Color(255,128,255,255),ct_testtile);
    AddColor(sf::Color(0  ,128,0  ,255),ct_point);
    AddColor(sf::Color(64 ,64 ,128,255),ct_startwall);
#undef AddColor
}
コード例 #16
0
void AnimaMappedValues::AddColor(const AnimaString& propertyName, AFloat r, AFloat g, AFloat b, AFloat a)
{
	AnimaColor4f color(r, g, b, a);
	AddColor(propertyName, color);
}
コード例 #17
0
ファイル: file.cpp プロジェクト: dberga/hpb_bot_plugin
BYTE AveragePixels (int count)
{
   float r,g,b;
   int   i;
   int   vis;
	int   pix;
	float dr, dg, db;
	float bestdistortion, distortion;
	int   bestcolor;

   vis = 0;
   r = g = b = 0;

   for (i = 0; i < count; i++)
   {
      pix = pixdata[i];
      r += linearpalette[pix][0];
      g += linearpalette[pix][1];
      b += linearpalette[pix][2];
   }

   r /= count;
   g /= count;
   b /= count;

   r += d_red;
   g += d_green;
   b += d_blue;
	
//
// find the best color
//
   bestdistortion = 3.0;
   bestcolor = -1;

   for (i = 0; i < 255; i++)
   {
      if (color_used[i])
      {
         pix = i;	//pixdata[i];

         dr = r - linearpalette[i][0];
         dg = g - linearpalette[i][1];
         db = b - linearpalette[i][2];

         distortion = dr*dr + dg*dg + db*db;
         if (distortion < bestdistortion)
         {
            if (!distortion)
            {
               d_red = d_green = d_blue = 0;	// no distortion yet
               return pix;		// perfect match
            }

            bestdistortion = distortion;
            bestcolor = pix;
         }
      }
   }

   if (bestdistortion > 0.001 && colors_used < 255)
   {
      bestcolor = AddColor( r, g, b );
      d_red = d_green = d_blue = 0;
      bestdistortion = 0;
   }
   else
   {
      // error diffusion
      d_red = r - linearpalette[bestcolor][0];
      d_green = g - linearpalette[bestcolor][1];
      d_blue = b - linearpalette[bestcolor][2];
   }

   if (bestdistortion > maxdistortion)
      maxdistortion = bestdistortion;

   return bestcolor;
}
コード例 #18
0
bool CVehicleColorManager::Load ( const char* szFilename )
{
    // Make sure we're cleared
    Reset ();

    // Load vehiclecolors.conf
    FILE* pFile = fopen ( szFilename, "r" );
    if ( pFile )
    {
        // Read each line of it
        char szBuffer [256];
        while ( !feof ( pFile ) )
        {
            // Grab the current line
            fgets ( szBuffer, 256, pFile );

            // Is this a comment?
            if ( szBuffer [0] != '#' )
            {
                // Split it up in vehicle id, color1, color2, color3 and color4
                char* szModel = strtok ( szBuffer, " " );
                char* szColor1 = strtok ( NULL, " " );
                char* szColor2 = strtok ( NULL, " " );
                char* szColor3 = strtok ( NULL, " " );
                char* szColor4 = strtok ( NULL, " " );

                // Set the colors that exist
                unsigned short usModel = 0;
                unsigned char ucColor1 = 0;
                unsigned char ucColor2 = 0;
                unsigned char ucColor3 = 0;
                unsigned char ucColor4 = 0;
                if ( szModel )
                {
                    usModel = static_cast < unsigned short > ( atol ( szModel ) );

                    if ( szColor1 )
                    {
                        ucColor1 = static_cast < unsigned char > ( atol ( szColor1 ) );

                        if ( szColor2 )
                        {
                            ucColor2 = static_cast < unsigned char > ( atol ( szColor2 ) );

                            if ( szColor3 )
                            {
                                ucColor3 = static_cast < unsigned char > ( atol ( szColor3 ) );

                                if ( szColor4 )
                                {
                                    ucColor4 = static_cast < unsigned char > ( atol ( szColor4 ) );
                                }
                            }
                        }
                    }

                    // Add it to the list
                    AddColor ( usModel, CVehicleColor ( ucColor1, ucColor2, ucColor3, ucColor4 ) );
                }
            }
        }

        // Close it
        fclose ( pFile );
        return true;
    }

    // Couldn't load the file
    return false;
}
コード例 #19
0
ファイル: biMVCA.cpp プロジェクト: ardielgr/MLSB_problem
void Graph::my_MVCA(Graph G) {
	int num,i,j,p,k,Add_p;
	int flag;
	int temp[CN];
   edge *e;
   int label_app[CN][VN]; // support variable
   int Labeli,Labelj;
   int app_Num_Comp[CN];

   Temporary_Vector=new int[G.cn];

   if (Demo==1){
   	printf("--- MVCA ---\n\n\n");
   	getch();
   }
   if (sol_cn!=0) RemoveAllColors();
   num=vn;
   //Add_p=0;
   flag=1;
	for (p=0; p<G.cn; p++){
      if (G.L[p].root==NULL) temp[p]=1;
      else temp[p]=0;
      if (Demo==1)	printf("temp[%d]=%d\n",p,temp[p]);
   }
   if (Demo==1)	getch();
   while (flag==1) {
      dim_Temp=0;
   	for (p=0; p<G.cn; p++) {
         if (Demo==1)	printf("temp[%d]=%d\n",p,temp[p]);
     		if (temp[p]==1) continue;
         for (i=0; i<vn; i++) {
      		label_app[p][i]=label[i];
            if (Demo==1)	printf("label_app[%d][%d]=%d, label[%d]=%d\n",p,i,label_app[p][i],i,label[i]);
         }
         app_Num_Comp[p]=NumComps;
         e=G.L[p].root;
         while (e!=NULL) {
			i=e->u;
         	j=e->v;
            if (Demo==1)	printf("\ni=%d, j=%d\n",i,j);
            if (i==j) {
        			e=e->next;
         		continue;
      		}
      		if(label_app[p][i]!=label_app[p][j]){
            	app_Num_Comp[p]=app_Num_Comp[p]-1;
         		Labeli=label_app[p][i];
         		Labelj=label_app[p][j];
         		for (k=0; k<vn; k++){	// := 1 to N
         			if (label_app[p][k]==Labelj)	label_app[p][k]=Labeli;
         		}
      		}
            if (Demo==1){
            	printf("e->next\n\n\n");
            	getch();
            }
      		e=e->next;
         }
         if (Demo==1){
         	getch();
         	printf("\nOLD TEMP num=%d\n",num);
         	getch();
         }
        	if (app_Num_Comp[p]<num) {
            Temporary_Vector[0]=p;
            dim_Temp=1;
				//Add_p=p;
            num=app_Num_Comp[p];
            if (Demo==1){
            	printf("\nNEW TEMP num=%d\n",num);
         		getch();
            }
         }
         else{
         	if ((app_Num_Comp[p]==num)&&(dim_Temp!=0)) {
               if (Demo==1)	printf("\nTHIS COLOR HAS THE SAME NUMBER OF CONN.COMPS. NEW ENTRY IN TEMPORARY VECTOR!\n");
            	Temporary_Vector[dim_Temp]=p;
         		dim_Temp++;
            }
         }
         if (Demo==1){
            printf("\nTEMPORARY VECTOR: ");
            for (i=0; i<dim_Temp; i++) {
            	printf("%d ",Temporary_Vector[i]);
            }
         	printf("\nWe start again with another color\n");
         	getch();
         }
      }
      if (Demo==1){
      	printf("\n!!!No we scan all the colors: we add the best color\n");
      	getch();
      }
      Add_p=Temporary_Vector[rand()%dim_Temp];
      AddColor(G,Add_p);
      temp[Add_p]=1;
      NumComps=num;
      if (Demo==1){
      	printf("\nPosition of the color added=%d, color added=%d, New num=%d\n",Add_p,G.L[Add_p].c,num);
      	getch();
      }
      for (i=0; i<vn; i++) {
         label[i]=label_app[Add_p][i];
         if (Demo==1)	printf("label[%d]=%d ",i,label[i]);
      }
      if (NumComps==1) flag=0;
      if (Demo==1){
      	printf("\nflag=%d\n",flag);
      	getch();
      }
   }
}
コード例 #20
0
// Add a solid color range to the list
BOOL CSliderCtrlEx::AddColor(int nLow, int nHigh, COLORREF color)
{
	return AddColor(nLow,nHigh,color,color);
}
コード例 #21
0
bool CXTPSyntaxEditColorComboBox::Init()
{
	// MFCBUG: adjust height so display is the same as non-owner drawn
	// CComboBoxes. MFC sets the height of an owner-drawn CComboBox
	// 2-3 pixels larger than a non owner-drawn combo.

	SetItemHeight(-1, (::GetSystemMetrics(SM_CYVTHUMB)-::GetSystemMetrics(SM_CYEDGE)));

	ResetContent();

	AddColor( RGB(0x00,0x00,0x00), XTP_IDS_CLR_BLACK ),
	AddColor( RGB(0xff,0xff,0xff), XTP_IDS_CLR_WHITE ),
	AddColor( RGB(0x80,0x00,0x00), XTP_IDS_CLR_MAROON ),
	AddColor( RGB(0x00,0x80,0x00), XTP_IDS_CLR_DARK_GREEN ),
	AddColor( RGB(0x80,0x80,0x00), XTP_IDS_CLR_OLIVE ),
	AddColor( RGB(0x00,0x00,0x80), XTP_IDS_CLR_DARK_BLUE ),
	AddColor( RGB(0x80,0x00,0x80), XTP_IDS_CLR_PURPLE ),
	AddColor( RGB(0x00,0x80,0x80), XTP_IDS_CLR_TEAL ),
	AddColor( RGB(0xC0,0xC0,0xC0), XTP_IDS_CLR_GRAY25 ),
	AddColor( RGB(0x80,0x80,0x80), XTP_IDS_CLR_GRAY50 ),
	AddColor( RGB(0xFF,0x00,0x00), XTP_IDS_CLR_RED ),
	AddColor( RGB(0x00,0xFF,0x00), XTP_IDS_CLR_GREEN ),
	AddColor( RGB(0xFF,0xFF,0x00), XTP_IDS_CLR_YELLOW ),
	AddColor( RGB(0x00,0x00,0xFF), XTP_IDS_CLR_BLUE ),
	AddColor( RGB(0xFF,0x00,0xFF), XTP_IDS_CLR_PINK ),
	AddColor( RGB(0x00,0xFF,0xFF), XTP_IDS_CLR_TURQUOISE ),

	SetCurSel(0);
	return true;
}
コード例 #22
0
void svlFilterImageColorSegmentation::AddColor(int x, int y, int z, unsigned char threshold, unsigned char label)
{
    AddColor(svlColorSpaceRGB, x, y, z, threshold, label);
}
コード例 #23
0
int main(int argc, char *argv[])
{
	int myid, numprocs;
	double starttime, endtime;	
	MPI_Status s;

	int  namelen;
	char processor_name[MPI_MAX_PROCESSOR_NAME];
    MPI_Init(&argc,&argv);
    MPI_Comm_size(MPI_COMM_WORLD,&numprocs);	
    MPI_Comm_rank(MPI_COMM_WORLD,&myid);
    MPI_Get_processor_name(processor_name,&namelen);	
	starttime = MPI_Wtime(); 	
	//F-Fusion, L-Low;
	unsigned char *colorData;

	int length=0;	
	
	unsigned char* colorBodyF,*colorBodyL;

	unsigned char* colorDataF,* colorDataL;

	unsigned char* colorHeadF, * colorHeadL;

	int HeightFusion,WidthFusion,LengthFusion;

	int HeightLow,WidthLow,LengthLow;

//	int length;
	int height,width;

	double *RGBF,*RGBL;      
    double  *colorBodyNew;	
	double RGBNewF[3];
	double RGBNewL[3];
  //  int colorLength, grayLength;
	int colorLength;
//	double eps = 0.000001;   //控制精度要求

  //  RGBF=(double*)malloc(sizeof(double)*3);
//	RGBL=(double*)malloc(sizeof(double)*3);
	
	
	printf("**********************************\n");

	fprintf(stdout,"Process %d of %d on %s\n",myid,numprocs,processor_name);

    if (myid==0)
	{
	
       	unsigned char* colorBody;	
		
	    ReadColorBmp("C:\\XXR_Image\\color.bmp", colorBodyF, colorHeadF,height,width, colorLength);

		ReadColorBmp("C:\\XXR_Image\\tm.bmp", colorBodyL, colorHeadL, height,width,colorLength);

		printf("colorLength=%d\n",colorLength);        

		while ((colorLength%numprocs)!=0)
		{
			numprocs--;
		}
		
		length=colorLength/numprocs;
		colorDataF=colorBodyF;
		colorDataL=colorBodyL;

		
		for (int i=1;i<numprocs;i++)
		{
			MPI_Send(&length,1,MPI_INT,i,20,MPI_COMM_WORLD);
			MPI_Send(colorBodyF+i*length*3,length*3,MPI_UNSIGNED_CHAR,i,21,MPI_COMM_WORLD);
		    MPI_Send(colorBodyL+i*length*3,length*3,MPI_UNSIGNED_CHAR,i,22,MPI_COMM_WORLD);
		}	
		
	}

	else
	{
		MPI_Status s;
		MPI_Recv(&length,1,MPI_INT,0,20,MPI_COMM_WORLD,&s);
		colorDataF=(unsigned char* )malloc(sizeof(unsigned char)*length*3);
        colorDataL=(unsigned char* )malloc(sizeof(unsigned char)*length*3);
		MPI_Recv(colorDataF,length*3,MPI_UNSIGNED_CHAR,0,21,MPI_COMM_WORLD,&s);
		MPI_Recv(colorDataL,length*3,MPI_UNSIGNED_CHAR,0,22,MPI_COMM_WORLD,&s);
	}
        	
    //printf("colorLength=%d\n",colorLength);
      printf("length=%d\n",length);     
	  AddColor(colorDataF, RGBF, length); 
	  AddColor(colorDataL, RGBL, length); 

		if (myid==0)
	{				
	    double *RGBDataF;   
        RGBDataF=(double*)malloc(sizeof(double)*3*numprocs);	
        MPI_Send(RGBF,3,MPI_DOUBLE,0,30,MPI_COMM_WORLD);
		MPI_Recv(RGBDataF,3,MPI_DOUBLE,0,30,MPI_COMM_WORLD,&s);

        double *RGBDataL;
        RGBDataL=(double*)malloc(sizeof(double)*3*numprocs);	
        MPI_Send(RGBL,3,MPI_DOUBLE,0,31,MPI_COMM_WORLD);
		MPI_Recv(RGBDataL,3,MPI_DOUBLE,0,31,MPI_COMM_WORLD,&s);

		
		for (int i=1;i<numprocs;i++)
		{
		//	MPI_Status s;
			MPI_Recv(RGBDataF+3*i,3,MPI_DOUBLE,i,33,MPI_COMM_WORLD,&s);
			MPI_Recv(RGBDataL+3*i,3,MPI_DOUBLE,i,34,MPI_COMM_WORLD,&s);
		}

		double temp0,temp1,temp2;
		temp0=0;
	    temp1=0;
	    temp2=0;

		for(int i=0;i<3;i++)
		{	   
		  RGBNewF[i]=0;
          RGBNewL[i]=0;
		}        
     
        for (int i=0;i<numprocs*3;)
		{         
		 temp0=RGBDataF[i++];           
         temp1=RGBDataF[i++];
         temp2=RGBDataF[i++];
           
	     RGBNewF[0]+=temp0;
		 RGBNewF[1]+=temp1;
		 RGBNewF[2]+=temp2;
		}

		RGBNewF[0]=RGBNewF[0]/colorLength;
        RGBNewF[1]=RGBNewF[1]/colorLength;
		RGBNewF[2]=RGBNewF[2]/colorLength; 

     	temp0=0;
	    temp1=0;
	    temp2=0;
		
        for (int i=0;i<numprocs*3;)
		{         
		 temp0=RGBDataL[i++];           
         temp1=RGBDataL[i++];
         temp2=RGBDataL[i++];
           
	     RGBNewL[0]+=temp0;
		 RGBNewL[1]+=temp1;
		 RGBNewL[2]+=temp2;
		}

      RGBNewL[0]=RGBNewL[0]/colorLength;
      RGBNewL[1]=RGBNewL[1]/colorLength;
      RGBNewL[2]=RGBNewL[2]/colorLength; 

      printf("RGBNewF[0]=%f,RGBNewF[1]=%f,RGBNewF[2]=%f\n\n",RGBNewF[0],RGBNewF[1],RGBNewF[2]);
	  printf("RGBNewL[0]=%f,RGBNewL[1]=%f,RGBNewL[2]=%f\n\n",RGBNewL[0],RGBNewL[1],RGBNewL[2]); 
     
	} 

	else
	{ 	
		MPI_Send(RGBF,3,MPI_DOUBLE,0,33,MPI_COMM_WORLD);
		MPI_Send(RGBL,3,MPI_DOUBLE,0,34,MPI_COMM_WORLD);
	}/**/

	 double *meanFRGB;
     meanFRGB=(double*)malloc(sizeof(double)*3);

	 double *meanLRGB;
     meanLRGB=(double*)malloc(sizeof(double)*3);

    if (myid==0)
	{				
      MPI_Send(&RGBNewL,3,MPI_DOUBLE,0,40,MPI_COMM_WORLD);
	  MPI_Recv(meanFRGB,3,MPI_DOUBLE,0,40,MPI_COMM_WORLD,&s);
	  MPI_Send(&RGBNewF,3,MPI_DOUBLE,0,41,MPI_COMM_WORLD);
	  MPI_Recv(meanLRGB,3,MPI_DOUBLE,0,41,MPI_COMM_WORLD,&s);

      for (int i=1;i<numprocs;i++)
		{
			 MPI_Send(&RGBNewL,3,MPI_DOUBLE,i,42,MPI_COMM_WORLD);
	         MPI_Send(&RGBNewF,3,MPI_DOUBLE,i,43,MPI_COMM_WORLD);
		}	
	}

	else
	{
		MPI_Recv(meanFRGB,3,MPI_DOUBLE,0,42,MPI_COMM_WORLD,&s);
		MPI_Recv(meanLRGB,3,MPI_DOUBLE,0,43,MPI_COMM_WORLD,&s);
	}

double *fenZiMuUpLowRGB;

ComputeCorrelationXS(colorDataF,colorDataL,meanFRGB,meanLRGB,fenZiMuUpLowRGB, length);

	if (myid==0)
	{				
	    double *fenZiMuRGBTotal;   
        fenZiMuRGBTotal=(double*)malloc(sizeof(double)*9*numprocs);	
        MPI_Send(fenZiMuUpLowRGB,9,MPI_DOUBLE,0,50,MPI_COMM_WORLD);
		MPI_Recv(fenZiMuRGBTotal,9,MPI_DOUBLE,0,50,MPI_COMM_WORLD,&s);

       		
		for (int i=1;i<numprocs;i++)
		{
		//	MPI_Status s;
		
			MPI_Recv(fenZiMuRGBTotal+9*i,9,MPI_DOUBLE,i,51,MPI_COMM_WORLD,&s);
		}
        
         double fenZiMuRGBCal[9];
			for (int i=0;i<9;i++)
				fenZiMuRGBCal[i]=0;

           
			for (int i=0;i<numprocs*9;)			
			{
		     	for (int k=0;k<9;k++)
					fenZiMuRGBCal[k]=fenZiMuRGBCal[k]+fenZiMuRGBTotal[i++];
			}

   double CorrelationXS[3];
   CorrelationXS[0]=fenZiMuRGBCal[0]/(sqrt(fenZiMuRGBCal[1]*fenZiMuRGBCal[2]));
   CorrelationXS[1]=fenZiMuRGBCal[3]/(sqrt(fenZiMuRGBCal[4]*fenZiMuRGBCal[5]));
   CorrelationXS[2]=fenZiMuRGBCal[6]/(sqrt(fenZiMuRGBCal[7]*fenZiMuRGBCal[8]));

   printf("CorrelationXS[0]=%f,CorrelationXS[1]=%f,CorrelationXS[2]=%f\n\n",CorrelationXS[0],CorrelationXS[1],CorrelationXS[2]);
   
	} 

	else
	{ 	
	MPI_Send(fenZiMuUpLowRGB,9,MPI_DOUBLE,0,51,MPI_COMM_WORLD);
	}
	
    MPI_Finalize(); 

/*		
	endtime = MPI_Wtime();
    printf("That takes %f seconds:\n",endtime-starttime);
    MPI_Finalize();  */

    return 0;
}
コード例 #24
0
ファイル: biMVCA.cpp プロジェクト: ardielgr/MLSB_problem
void Graph::pp_MVCA(Graph G) {
	int num,numC,numB;
	int i,j,p,k,Add_p;
	int flag;
	int temp[CN];
   edge *e;
   Adj_item *a,*aa;
   int label_app[CN][VN]; // support variable
   int label_appB[CN][VN]; // support variable
   int Labeli,Labelj,Labelk;
   int app_Num_Comp[CN];
   int app_Num_Blocks[CN];
   int path[VN];
   int Queue[VN];
   int q,Qlast;
   int ii; // index for the "for" sentence

   Temporary_Vector=new int[G.cn];

if (Demo==1){ printf("--- pp MVCA ---\n\n\n");
getch();
}

if (Demo==2){ printf("--- pp MVCA ---\n\n\n");
getch();
}


   if (sol_cn!=0) RemoveAllColors();
   
   numC = vn ;
   numB = vn ;
   num = numC + numB ; 

   //Add_p=0;
   flag=1;
	for (p=0; p<G.cn; p++)
      if (G.L[p].root==NULL) 
			temp[p]=1;
      else temp[p]=0;
      
if (Demo==1){
printf("\n Color = ");
for (int ii=0; ii<G.cn; ii++)	printf("%3d",ii);
printf("\n Temp = [");
for (int ii=0; ii<G.cn; ii++)	printf("%3d",temp[ii]);
printf("]\n ");
getch();
}

	for (int i=0; i<vn; i++) 
		Adj[i]=NULL ;
		
   while (flag==1) {
		dim_Temp=0;    
   	for (p=0; p<G.cn; p++) {

if (Demo==1) printf("NEW p: temp[%d]=%d\n",p,temp[p]);

     	if (temp[p]==1) continue;
      for (i=0; i<vn; i++) {
      	label_app[p][i]=label[i];
      	label_appB[p][i]=labelB[i];
			}

if (Demo==1){
printf("\n p =%2d. i: ",p);
for (int ii=0; ii<vn; ii++) printf("%3d",ii);   
printf("\n    label: ");
for (int ii=0; ii<vn; ii++) printf("%3d",label[ii]);
printf("\n label_app:");
for (int ii=0; ii<vn; ii++) printf("%3d",label_app[p][ii]);
printf("\n   labelB: ");
for (int ii=0; ii<vn; ii++) printf("%3d",labelB[ii]);
printf("\nlabel_appB:");
for (int ii=0; ii<vn; ii++) printf("%3d",label_appB[p][ii]);
printf("\n\n");
}
         
      app_Num_Comp[p]=NumComps;
      app_Num_Blocks[p]=NumBlocks;

if (Demo==2) printf("\nColor %d:",p);

if (Demo==1) {
printf("\nColor %d:",p);
e=G.L[p].root;
while (e!=NULL) {
	printf("(%d,%d) ",e->u,e->v);
	e=e->next;
	}
printf(" \n");
}
         
		e=G.L[p].root;
      while (e!=NULL) {
			i=e->u;
         j=e->v;
         	
if (Demo==1) printf("\nColor %d: edge (i=%d, j=%d)\n",p,i,j);

      	if (i==j) {
       		e=e->next;
         	continue;
				}
      		
      	if(label_app[p][i]!=label_app[p][j]) {
            app_Num_Comp[p]=app_Num_Comp[p]-1;
         	Labeli=label_app[p][i];
         	Labelj=label_app[p][j];
         	for (k=0; k<vn; k++) {	
					if (label_app[p][k]==Labelj)	
		 				label_app[p][k]=Labeli;
         		}
      		}
      	else {
				if(label_appB[p][i]!=label_appB[p][j]) {

if (Demo==1){
printf(" Need the path from %d to %d:\n",i,j);
printf(" With Adj lists:\n");
for(int ii=0;ii<vn;ii++){
	printf("%3d: ",ii);
	a = Adj[ii];
	while (a!=NULL){
		printf(" %3d",a->v);
		a=a->next;
		}
	printf("\n");
	}
getch();
}      			
					// BFS for the shortest path from i to j
      			for (k=0; k<vn; k++)	
         			path[k]=vn;
         		path[j]=j;
         		Queue[0]=j;
         		q = 0 ;
         		Qlast = 0 ;
         		do{
         			a = Adj[Queue[q]];
         			while (a!=NULL){
         				if (path[a->v]==vn){
         					path[a->v]=Queue[q];
         					Qlast++;
         					Queue[Qlast]=a->v;
								}
         				a=a->next ;
							}
         				q++;
						} while (path[i]==vn);
					// End of the BFS
         		// The path is i, path[i], path[path[i]], ..., j
         		

if (Demo==1){
printf("\n PATH ARRAY:");
for (ii=0; ii<vn; ii++) printf("%3d",path[ii]);
printf("\n PATH: ");
ii = i;
while(ii!=j){
	printf("%3d",ii);
	ii = path[ii];
}
printf("%3d.\n",ii);
getch();
}
         		
         		// Traverse the path from i to j joining the blocks found
      			Labeli = label_appB[p][i];
         		k = i ;
      			do{
				  		k = path[k] ;
				  		if(label_appB[p][k]!=Labeli) {
							app_Num_Blocks[p] = app_Num_Blocks[p] - 1;
				  			Labelk = label_appB[p][k] ;
				  			for(int q=0; q<vn; q++)
				  				if (label_appB[p][q]==Labelk)
				  					label_appB[p][q]= Labeli ;
							}
						} while (k!=j);
				   if (Demo==1) printf(" Num of Blocks down to: %d",app_Num_Blocks[p]) ;
      			} // END OF if(label_appB[p][i]!=label_appB[p][j]){
      		} // END of ELSE
      		
if (Demo==1){
printf(" Comps = %d, Blocks = %d",app_Num_Comp[p],app_Num_Blocks[p]);
printf("\n p =%2d. i: ",p);
for (int i=0; i<vn; i++) printf("%3d",i);   
printf("\n label_app:");
for (int i=0; i<vn; i++) printf("%3d",label_app[p][i]);
printf("\nlabel_appB:");
for (int i=0; i<vn; i++) printf("%3d",label_appB[p][i]);
printf("\n");
getch();
}

      	a=new Adj_item;
			a->v=i;
        	a->c=p;
        	a->next=Adj[j];
        	Adj[j]=a;
        
      	a=new Adj_item;
			a->v=j;
        	a->c=p;
        	a->next=Adj[i];
        	Adj[i]=a;
              		
      	e=e->next;
         } // END of WHILE e!= NULL
         
if (Demo==1){
printf(" END of WHILE (e!=NULL)\n");
printf(" OLD TEMP num = %d\n",num);
getch();
}

if (Demo==2) printf(" num = %d = %d + %d ",app_Num_Comp[p] + app_Num_Blocks[p],app_Num_Comp[p],app_Num_Blocks[p]);

      if (app_Num_Comp[p] + app_Num_Blocks[p]<num) {
         Temporary_Vector[0]=p;
         dim_Temp=1;
				//Add_p=p;
         numC = app_Num_Comp[p] ;
         numB = app_Num_Blocks[p] ;
         num = numC + numB;

if (Demo==2)printf("\nNEW TEMP num = %d = %d + %d ",num,numC,numB);

if (Demo==1){
printf("\nNEW TEMP num = %d = %d + %d \n",num,numC,numB);
getch();
}
         }
      else{
         if (((app_Num_Comp[p] + app_Num_Blocks[p])==num)&&(dim_Temp!=0)) {

if (Demo==2) printf("\nTHIS COLOR HAS THE SAME NUMBER OF COMPS+BLOCKS. NEW ENTRY IN TEMPORARY VECTOR!");


if (Demo==1){
printf("\nTHIS COLOR HAS THE SAME NUMBER OF COMPS+BLOCKS.");
printf(" NEW ENTRY IN TEMPORARY VECTOR!\n");
}
            	Temporary_Vector[dim_Temp]=p;
         		dim_Temp++;
            }
         }

if (Demo==1){
printf("\nTEMPORARY VECTOR: [");
for (int i=0; i<dim_Temp; i++) 
   printf("%3d ",Temporary_Vector[i]);
printf("]\n ");
printf("\n\nWe start again with another color\n");
getch();
}
         
      // Deleting color p from Adjacency lists
if (Demo==1) printf("\n Deleting color %d :",p);
         for (int i=0; i<vn; i++){
if (Demo==1) printf("\n From Adj[%d]: ",i);
         	while(Adj[i]!=NULL){
if (Demo==1) printf(" %d(%d) ",Adj[i]->v,Adj[i]->c);
         		if (Adj[i]->c == p) {
         			a = Adj[i];
if (Demo==1) printf(" X%d ",Adj[i]->v);
						Adj[i] = Adj[i]->next;
         	  		delete[] a;
						}
					else break;
					}
				if (Adj[i]!=NULL){
         		a = Adj[i] ;
if (Demo==1) printf(" %d(%d) ",Adj[i]->v,Adj[i]->c);
         		while((a->next)!=NULL){
if (Demo==1) printf(" %d(%d) ",(a->next)->v,(a->next)->c);
         			if ((a->next)->c == p) {
         				aa = a->next ;
if (Demo==1) printf(" X%d ",aa->v);
							a->next = aa->next ;
         	  			delete[] aa;
         	  			}
						else 
							a=a->next;
						}
					}
				}

if (Demo==2) getch();         
if (Demo==1) getch();         

      } // End of for p

if (Demo==2){
printf("\n!!!We have scanned all the colors: we add the best color among\n");
printf("\nTEMPORARY VECTOR: [");
for (int i=0; i<dim_Temp; i++) 
   printf("%3d ",Temporary_Vector[i]);
printf("]\n ");
getch();
}
      
if (Demo==1){
printf("\n!!!No we scan all the colors: we add the best color\n");
getch();
}
   Add_p=Temporary_Vector[rand()%dim_Temp];
   AddColor(G,Add_p);
   temp[Add_p]=1;
   numC = app_Num_Comp[Add_p] ;
   numB = app_Num_Blocks[Add_p] ;
   
   NumComps=numC;
   NumBlocks=numB;

if (Demo==2){
printf("\nPosition of the color added=%d, color added=%d, New num=%d\n",Add_p,G.L[Add_p].c,num);
getch();
}


if (Demo==1){
printf("\nPosition of the color added=%d, color added=%d, New num=%d\n",Add_p,G.L[Add_p].c,num);
getch();
}
   for (i=0; i<vn; i++) {
      label[i]=label_app[Add_p][i];
      labelB[i]=label_appB[Add_p][i];
   }

if (Demo>0) {
printf("\n    i :");
for (int i=0; i<vn; i++) printf("%3d",i);   
printf("\n label:");
for (int i=0; i<vn; i++) printf("%3d",label[i]);
printf("\nlabelB:");
for (int i=0; i<vn; i++) printf("%3d",labelB[i]);
printf("\n\n");
}
      
	e=G.L[Add_p].root;
   while (e!=NULL) {
		i=e->u;
      j=e->v;
      if (i==j) {
       	e=e->next;
         continue;
      	}
      		
      a=new Adj_item;
		a->v=i;
      a->c=Add_p;
      a->next=Adj[j];
      Adj[j]=a;
        
      a=new Adj_item;
		a->v=j;
   	a->c=Add_p;
      a->next=Adj[i];
      Adj[i]=a;
      e = e->next; 
	}


if (Demo>0){
printf(" Adj lists:\n");
for(int ii=0;ii<vn;ii++){
	printf("%3d: ",ii);
	a = Adj[ii];
	while (a!=NULL){
		printf(" %3d",a->v);
		a=a->next;
		}
	printf("\n");
	}
getch();
}      			
      
      if (NumBlocks==1) flag=0;

if (Demo==2){
printf("\nflag=%d\n",flag);
getch();
}
      
if (Demo==1){
printf("\nflag=%d\n",flag);
getch();
}

	} // END OF WHILE flag == 1
}
コード例 #25
0
void AnimaMappedValues::AddColor(const AnimaString& propertyName, AnimaColor3f value)
{
	AnimaColor4f color(value, 1.0f);
	AddColor(propertyName, color);
}