vtkSmartPointer<vtkAlgorithm> GlyphMagnitudeColorMapping::createFilter(AbstractVisualizedData & visualizedData, unsigned int port)
{
    if (port != 0)
    {
        return vtkSmartPointer<vtkPassThrough>::New();
    }

    const auto filterIt = m_filters.find(&visualizedData);

    // Return already created filter (in this case, visualizedData is valid for this mapping)
    if (filterIt != m_filters.end())
    {
        return filterIt->second;
    }

    // Check if the mapping can be applied to the provided visualization
    const auto glyphMappingDataIt = m_glyphMappingData.find(static_cast<RenderedData3D *>(&visualizedData));
    if (glyphMappingDataIt == m_glyphMappingData.end())
    {
        return vtkSmartPointer<vtkPassThrough>::New();
    }

    // Create the mapping pipeline
    assert(glyphMappingDataIt->second);
    auto & glyphMappingData = *glyphMappingDataIt->second;

    auto norm = vtkSmartPointer<vtkVectorNorm>::New();
    norm->SetInputConnection(glyphMappingData.vectorDataOutputPort());

    auto assignVectors = vtkSmartPointer<vtkAssignAttribute>::New();
    assignVectors->Assign(m_vectorName.toUtf8().data(), vtkDataSetAttributes::VECTORS, vtkAssignAttribute::POINT_DATA);
    assignVectors->SetInputConnection(norm->GetOutputPort());

    auto setArrayName = vtkSmartPointer<ArrayChangeInformationFilter>::New();
    setArrayName->EnableRenameOn();
    setArrayName->SetArrayName(s_normScalarsName);
    setArrayName->SetAttributeType(vtkDataSetAttributes::SCALARS);
    setArrayName->SetAttributeLocation(IndexType::points);
    setArrayName->SetInputConnection(assignVectors->GetOutputPort());

    m_filters[&visualizedData] = setArrayName;

    return setArrayName;
}
Example #2
0
//static variables 
GLuint ab=0;	

#define BUFFER_OFFSET(i) ((char *)NULL + (i))

int main ()
{
	int i=0;
	int ab=0;
	float clr[3] = {0.0f, 0.3f, 0.6f};
	float add[3] = {0.001f, 0.002f, 0.003f};
	unsigned int position_attrib_idx = 0;

	//GL stuff
	SShader vertexShader;
	SShader fragmentShader;
	SShaderProgram program;

	CPlatform platform;
	Create(&platform, "", 2, 1, 1024, 768, 8, 8, 8, 8, 16, 8, 0);	

	//-------------------
	//setup the shaders
	CreateShader(&vertexShader, VERT, &pVertexShader, 1);	
	CreateShader(&fragmentShader, FRAG, &pFragmentShader, 1);	
	
	CreateShaderProgram(&program);
	AddShaderToProgram(&program, &vertexShader);
	AddShaderToProgram(&program, &fragmentShader);
	SetAttributeLocation(&program, position_attrib_idx, "position");	//needs to be calleb before linking
	LinkShaderProgram(&program);	
	
	glGenBuffers(1, &ab);		//array buffer	
	//fill buffers
	glBindBuffer(GL_ARRAY_BUFFER, ab);
	glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

	//-------------------
	//tell openGL how to interperet the data
	glBindBuffer(GL_ARRAY_BUFFER, ab);
	glEnableVertexAttribArray(0);	
	glVertexAttribPointer(position_attrib_idx, 3, GL_FLOAT, GL_FALSE, 12, 0);

	//set rendering states
	glEnable(GL_CULL_FACE);	
	glClearColor(0, 0, 0, 0.0f); //alpha to 0, should make triangle appear over console
	Start(&program); //even when glDeleteProgram is called the program won't be deleted until it is out of use
	while (!IS_BUTTON_PRESSED(platform.m_keyboard.key[KB_ESC]))
	{
		Tick(&platform);
		glClear(GL_COLOR_BUFFER_BIT);
		SetVec3ByName(&program, "uColour", clr);
		glDrawArrays( GL_TRIANGLES, 0, 3);	
		SwapBuffers(&platform);

		for(i=0;i<3;i++)
		{
			clr[i]+=add[i];
			if(clr[i]>1.0f)add[i]*=-1.0f;		
			if(clr[i]<0.0f)add[i]*=-1.0f;
		}
	}
	Stop();