Example #1
0
// add a GMM array for vtkPointData
void addVtkGmmArrays(vtkPointData *vtk_point_data, AbstractDistrArray *array, const string &array_name, int GMs)
{
  printf("Gaussian Models in GaussianMixture=%d\n", GMs);
  char name[256];
  int i;
  int n = array->getLength();
  int nc = array->getNumComponents();

  for (i=0; i<GMs*3; i++)
  {
    vtkFloatArray *vtk_array = vtkFloatArray::New();
    vtk_array->SetNumberOfComponents( nc );
    vtk_array->SetNumberOfTuples( n );

    if (i%3==0) {
      sprintf(name, "%smean%d", array_name.c_str(), i/3);
      vtk_array->SetName(name);
      for (int j=0; j<n; j++)
      {
        vector<dist::Variant> vdist = array->getDistrVector(j);
        for (int c=0; c<nc; c++)
        {
          ((float *)vtk_array->GetVoidPointer(j))[c] = getGmmModels(vdist[c], GMs, i / 3).m;
        }
      }

    } else if (i%3==1) {
      sprintf(name, "%svar%d", array_name.c_str(), i/3);
      vtk_array->SetName(name);

      for (int j=0; j<n; j++)
      {
        vector<dist::Variant> vdist = array->getDistrVector(j);
        for (int c=0; c<nc; c++)
        {
          ((float *)vtk_array->GetVoidPointer(j))[c] = getGmmModels(vdist[c], GMs, i / 3).v;
        }
      }

    } else {
      sprintf(name, "%sweight%d", array_name.c_str(), i/3);
      vtk_array->SetName(name);

      for (int j=0; j<n; j++)
      {
        vector<dist::Variant> vdist = array->getDistrVector(j);
        for (int c=0; c<nc; c++)
        {
          ((float *)vtk_array->GetVoidPointer(j))[c] = getGmmModels(vdist[c], GMs, i / 3).w;
        }
      }

    }

    vtk_point_data->AddArray(vtk_array);
  }
}
Example #2
0
	void writeGmmArrays(ofstream & myFile, DistrArray *array, int GMs)
	{
		//1. number of array components
		//2. Is # of Gaussian components uniform (1-yes, 0-no)
		int nc = array->getNumComponents();
		myFile.write((char*)(&nc), sizeof (int));
		int isNumGaussianUniform = 1;
		myFile.write((char*)(&isNumGaussianUniform), sizeof (int));

		if (isNumGaussianUniform == 1){
			//3. # of Gaussian components
			myFile.write((char*)(&GMs), sizeof (int));

			//write data
			int n = array->getLength();
			float* gmData = new float[GMs * 3 * nc*n];		
			for (int c = 0; c < nc; c++){
				for (int j = 0; j < n; j++){
					for (int i = 0; i < GMs * 3; i++){
						int index = c*n*GMs * 3 + j*GMs * 3 + i;
						vector<dist::Variant> vdist = array->getDistrVector(j);
						if (i % 3 == 0)
							gmData[index] = getGmmModels(vdist[c], GMs, i / 3).m;
						else if (i % 3 == 1)
							gmData[index] = getGmmModels(vdist[c], GMs, i / 3).v;
						else
							gmData[index] = getGmmModels(vdist[c], GMs, i / 3).w;
					}
				}
			}

			myFile.write((char*)(gmData), sizeof (float)*GMs * 3 * nc*n);

			delete gmData;
		}
		/*
		printf("Gaussian Models in GaussianMixture=%d\n", GMs);
		char name[256];
		int i;

		for (i = 0; i<GMs * 3; i++)
		{
			vtkFloatArray *vtk_array = vtkFloatArray::New();
			vtk_array->SetNumberOfComponents(nc);
			vtk_array->SetNumberOfTuples(n);

			if (i % 3 == 0) {
				sprintf(name, "%smean%d", array_name.c_str(), i / 3);
				vtk_array->SetName(name);
				for (int j = 0; j<n; j++)
				{
					vector<dist::Variant> vdist = array->getDistrVector(j);
					for (int c = 0; c<nc; c++)
					{
						((float *)vtk_array->GetVoidPointer(j))[c] = getGmmModels(vdist[c], GMs, i / 3).m;
					}
				}

			}
			else if (i % 3 == 1) {
				sprintf(name, "%svar%d", array_name.c_str(), i / 3);
				vtk_array->SetName(name);

				for (int j = 0; j<n; j++)
				{
					vector<dist::Variant> vdist = array->getDistrVector(j);
					for (int c = 0; c<nc; c++)
					{
						((float *)vtk_array->GetVoidPointer(j))[c] = getGmmModels(vdist[c], GMs, i / 3).v;
					}
				}

			}
			else {
				sprintf(name, "%sweight%d", array_name.c_str(), i / 3);
				vtk_array->SetName(name);

				for (int j = 0; j<n; j++)
				{
					vector<dist::Variant> vdist = array->getDistrVector(j);
					for (int c = 0; c<nc; c++)
					{
						((float *)vtk_array->GetVoidPointer(j))[c] = getGmmModels(vdist[c], GMs, i / 3).w;
					}
				}

			}

			vtk_point_data->AddArray(vtk_array);
		}

		*/
	}