void test()
{
    SpectrumListSimplePtr simple(new SpectrumListSimple);

    const size_t spectrumCount = 10;
    for (size_t i=0; i<spectrumCount; i++)
    {
        simple->spectra.push_back(SpectrumPtr(new Spectrum));
        Spectrum& s = *simple->spectra.back();
        s.index = i;
        s.id = "scan=" + lexical_cast<string>(i);
    }

    // check MyWrapper 

    shared_ptr<MyWrapper> wrapper(new MyWrapper(simple)); 

    wrapper->verifySize(10);
    unit_assert(wrapper->size() == 10);
    for (size_t i=0; i<spectrumCount; i++)
    {
        string id = "scan=" + lexical_cast<string>(i);

        unit_assert(wrapper->find(id) == i);
        IndexList indexList = wrapper->findNameValue("scan", lexical_cast<string>(i));
        unit_assert(indexList.size()==1 && indexList[0]==i);

        const SpectrumIdentity& identity = wrapper->spectrumIdentity(i);
        unit_assert(identity.id == id);

        SpectrumPtr s = wrapper->spectrum(i);
        unit_assert(s->id == id);
    }

    // check FilterWrapper

    shared_ptr<FilterWrapper> filterWrapper(new FilterWrapper(simple)); 

    unit_assert(filterWrapper->size() == 5);

    for (size_t i=0; i<filterWrapper->size(); i++)
    {
        string id = "scan=" + lexical_cast<string>(i*2);
        string scanNumber = lexical_cast<string>(i*2);

        unit_assert(filterWrapper->find(id) == i);
        IndexList indexList = filterWrapper->findNameValue("scan", scanNumber);
        unit_assert(indexList.size()==1 && indexList[0]==i);

        const SpectrumIdentity& identity = filterWrapper->spectrumIdentity(i);
        unit_assert(identity.id == id);

        SpectrumPtr s = filterWrapper->spectrum(i);
        unit_assert(s->id == id);
    }
}
Example #2
0
File: Sky.cpp Project: jcrm/DX
void Sky::init(ID3D10Device* device, ID3D10ShaderResourceView* cubemap, float radius){
	md3dDevice = device;
	mCubeMap   = cubemap;
	mVertexType = 1;

	mTech			= fx::SkyFX->GetTechniqueByName("SkyTech");
	mfxWVPVar		= fx::SkyFX->GetVariableByName("gWVP")->AsMatrix();
	mfxWorldVar		= fx::SkyFX->GetVariableByName("gWorld")->AsMatrix();
	mfxCubeMapVar	= fx::SkyFX->GetVariableByName("gCubeMap")->AsShaderResource();

	std::vector<D3DXVECTOR3> vertices;
	IndexList indices;

	BuildGeoSphere(2, radius, vertices, indices);

	VertexList skyVerts(vertices.size());
	for(size_t i = 0; i < vertices.size(); ++i){
		// Scale on y-axis to turn into an ellipsoid to make a flatter Sky surface
		skyVerts[i].pos = 0.5f*vertices[i];
	}
	mNumVertices = skyVerts.size();
	GfxObj::buildVB(skyVerts);

	mNumIndices = (UINT)indices.size();
	mNumFaces = mNumIndices*3;

	GfxObj::buildIB(indices);
}
Example #3
0
double scn::Ruler::GetCyclicCoeff(size_t indexOfNode)
{
   IndexList edges;
   auto& distance = distance_sssp;
   distance.clear();
   if(indexOfNode != UGraph::NaF)
   {//one vertex
      tie(edges, std::ignore) = graph->RemoveNode(indexOfNode);
      double sum = 0;
      for(auto head = edges.begin(); head != edges.end(); head++)
      {
	 RunSPFA(*head);
	 for(auto tail = head + 1; tail != edges.end(); tail++)
	 {
	    sum += 1.0 / static_cast<double>(distance[*tail] + 2);
	 }
      }
      ///restore
      graph->AddEdge(graph->AddNode(indexOfNode), edges);
      return 2 * sum / static_cast<double>(edges.size() * (edges.size() - 1));
   }
   else
   {//the whole network
      //copy node list
      IndexList nodes = graph->CopyIndexOfNodes();
      double total_sum = 0;
      for(auto node = nodes.begin(); node != nodes.end(); node++)
      {
	 tie(edges, std::ignore) = graph->RemoveNode(*node);
	 double sum = 0;
	 for(auto head = edges.begin(); head != edges.end(); head++)
	 {
	    RunSPFA(*head);
	    for(auto tail = head + 1; tail != edges.end(); tail++)
	    {
	       sum += 1.0 / static_cast<double>(distance[*tail] + 2);
	    }
	 }
	 ///restore, add node first, then add list of edges of this node
	 graph->AddEdge(graph->AddNode(*node), edges);
	 //accumulate
	 total_sum += 2 * sum / static_cast<double>(edges.size() * (edges.size() - 1));
      }
      return total_sum / static_cast<double>(graph->GetNumberOfNodes());
   }
}
Example #4
0
 inline void operator() (Lattice& L, IndexList& idx)
 {
     typedef typename Lattice::element element;
     for(int dim = 0; dim < idx.size(); ++dim)
     {
         sum += L(idx) * L.get_n_left(idx, dim);
         sum += L(idx) * L.get_n_right(idx, dim);
     }
 }
Example #5
0
void Mesh::construct()
{
	if (!m_material || !m_geometry) {
		return;
	}

	destruct();

	glGenVertexArrays(1, &m_vertexArray);
	glBindVertexArray(m_vertexArray);

	// Fill vertex position data
	glGenBuffers(1, &m_vertexBuffer);
	glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer);

	VertexList vertices = m_geometry->vertices();
	glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(glm::vec3), vertices.data(), GL_STATIC_DRAW);

	glVertexAttribPointer((GLint)ShaderAttribute::VertexPosition, 3, GL_FLOAT, GL_FALSE, 0, bufferOffset(0));
	glEnableVertexAttribArray((GLint)ShaderAttribute::VertexPosition);

	// Fill UV vertex data
	if (m_geometry->uvCount()) {
		glGenBuffers(1, &m_textureCoordinatesBuffer);
		glBindBuffer(GL_ARRAY_BUFFER, m_textureCoordinatesBuffer);

		UVList uvs = m_geometry->uvs();
		glBufferData(GL_ARRAY_BUFFER, uvs.size() * sizeof(glm::vec2), uvs.data(), GL_STATIC_DRAW);

		glVertexAttribPointer((GLint)ShaderAttribute::VertexTextureCoordinates, 2, GL_FLOAT, GL_FALSE, 0, bufferOffset(0));
		glEnableVertexAttribArray((GLint)ShaderAttribute::VertexTextureCoordinates);
	}

	// Fill vertex normal data
	if (m_geometry->normalCount()) {
		glGenBuffers(1, &m_vertexNormalsBuffer);
		glBindBuffer(GL_ARRAY_BUFFER, m_vertexNormalsBuffer);

		VertexList normals = m_geometry->normals();
		glBufferData(GL_ARRAY_BUFFER, normals.size() * sizeof(glm::vec3), normals.data(), GL_STATIC_DRAW);

		glVertexAttribPointer((GLint)ShaderAttribute::VertexNormals, 3, GL_FLOAT, GL_FALSE, 0, bufferOffset(0));
		glEnableVertexAttribArray((GLint)ShaderAttribute::VertexNormals);
	}

	// Fill index buffer
	glGenBuffers(1, &m_indexBuffer);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indexBuffer);

	IndexList indices = m_geometry->indices();
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(uint32_t), indices.data(), GL_STATIC_DRAW);

	glBindVertexArray(0);

	m_dirty = false;
}
Example #6
0
 inline void operator() (Lattice& L, IndexList& idx) 
 {
     typename Lattice::element delta = 0;
     for(int dim = 0; dim < idx.size(); ++dim)
     {
         delta += L.get_n_left(idx, dim);
         delta += L.get_n_right(idx, dim);
     }
     L(idx) += delta;
 }
Example #7
0
void medTestDbApp::handleNonPersistentDataImported()
{
    CHECK_TEST_RESULT(importedIndex.isValid());
    CHECK_TEST_RESULT(importedIndex.isValidForSeries());

    const int persistentSourceId = 1;
    const int nonPersistentSourceId = 2;

    // Check freshly imported data exists.
    npDb = dataManager->controllerForDataSource(nonPersistentSourceId);
    CHECK_TEST_RESULT( npDb );
    CHECK_TEST_RESULT(npDb->dataSourceId() == nonPersistentSourceId);
    CHECK_TEST_RESULT( !npDb->isPersistent() );

    typedef QList<medDataIndex> IndexList;
    IndexList patients = npDb->patients();
    qDebug() << "patient size:"<< patients.size();
    CHECK_TEST_RESULT(patients.size() == 1);
    CHECK_TEST_RESULT(patients[0].patientId() == importedIndex.patientId());
    IndexList studies = npDb->studies(patients[0]);
    CHECK_TEST_RESULT(studies.size() == 1);
    CHECK_TEST_RESULT(studies[0].studyId() == importedIndex.studyId());
    IndexList series = npDb->series(studies[0]);
    CHECK_TEST_RESULT(series.size() == 1);
    CHECK_TEST_RESULT(series[0].seriesId() == importedIndex.seriesId());

    // Ensure persistent DB is empty at first
    db = dataManager->controllerForDataSource(persistentSourceId);
    CHECK_TEST_RESULT( db );

    CHECK_TEST_RESULT( db->patients().size() == 0 );

    // Test import from non-Persistent to persistent
    //disconnect(dataManager);
    disconnect(dataManager, 0, this, 0);
    connect(dataManager, SIGNAL(dataAdded(const medDataIndex&)), this, SLOT(onPersistentDataImported(const medDataIndex&)));
    //TODO: reeanble this test when fixing supported extension bug,
    //and priority list!
    //dataManager->storeNonPersistentSingleDataToDatabase(importedIndex);
    //when reenabling, remove these two lines
    testResult = DTK_SUCCEED;
    exit();
}
Example #8
0
//***************************************************************************************
// Name: Subdivide
// Desc: Function subdivides every input triangle into four triangles of equal area.
//***************************************************************************************
void Subdivide(VertexList& vertices, IndexList& indices)
{
	VertexList vin = vertices;
	IndexList  iin = indices;

	vertices.resize(0);
	indices.resize(0);

	//       v1
	//       *
	//      / \
	//     /   \
	//  m0*-----*m1
	//   / \   / \
	//  /   \ /   \
	// *-----*-----*
	// v0    m2     v2

	UINT numTris = (UINT)iin.size()/3;
	for(UINT i = 0; i < numTris; ++i)
	{
		D3DXVECTOR3 v0 = vin[ iin[i*3+0] ];
		D3DXVECTOR3 v1 = vin[ iin[i*3+1] ];
		D3DXVECTOR3 v2 = vin[ iin[i*3+2] ];

		D3DXVECTOR3 m0 = 0.5f*(v0 + v1);
		D3DXVECTOR3 m1 = 0.5f*(v1 + v2);
		D3DXVECTOR3 m2 = 0.5f*(v0 + v2);

		vertices.push_back(v0); // 0
		vertices.push_back(v1); // 1
		vertices.push_back(v2); // 2
		vertices.push_back(m0); // 3
		vertices.push_back(m1); // 4
		vertices.push_back(m2); // 5
 
		indices.push_back(i*6+0);
		indices.push_back(i*6+3);
		indices.push_back(i*6+5);

		indices.push_back(i*6+3);
		indices.push_back(i*6+4);
		indices.push_back(i*6+5);

		indices.push_back(i*6+5);
		indices.push_back(i*6+4);
		indices.push_back(i*6+2);

		indices.push_back(i*6+3);
		indices.push_back(i*6+1);
		indices.push_back(i*6+4);
	}
}
Example #9
0
void medTestDbApp::handlePersistentDataImported()
{
    CHECK_TEST_RESULT( db->patients().size() == 1 );
    CHECK_TEST_RESULT( npDb->patients().size() == 0 );
    typedef QList<medDataIndex> IndexList;
    IndexList patients = db->patients();
    CHECK_TEST_RESULT(patients.size() == 1);
    IndexList studies = db->studies(patients[0]);
    CHECK_TEST_RESULT(studies.size() == 1);
    IndexList series = db->series(studies[0]);
    CHECK_TEST_RESULT(series.size() == 1);

    const medDataIndex persImportedIndex = series[0];

    this->processEvents();

    // clear cache.
    dataManager->clearCache();

    // Check data in db matches original.
    dtkSmartPointer<dtkAbstractData> testDataFromDb = dataManager->data( persImportedIndex );
    CHECK_TEST_RESULT(testDataFromDb->identifier() == testData->identifier());
    CHECK_TEST_RESULT(medMetaDataKeys::PatientName.getFirstValue(testDataFromDb) ==
                      medMetaDataKeys::PatientName.getFirstValue(testData));

    // Check removing works ok - need to use synchronous version.
    //dataManager->removeData( persImportedIndex );
    //this->processEvents();
    medDatabaseRemover remover( persImportedIndex );
    remover.run();

    // Should be no patients now.
    patients = db->patients();
    CHECK_TEST_RESULT(patients.size() == 0);

    //close db?
    medDatabaseController::instance()->closeConnection();
    testResult = DTK_SUCCEED;
    exit();
}
Example #10
0
double scn::GetRichClubCoeff(UGraph::pGraph graph,size_t degree)
{
   IndexList setOfHighNode;//whose degree is greater than
                           //argument degree
   for(auto node = graph->begin(); node != graph->end(); node++)
   {
      if(node->GetDegree() > degree)
      {
	 setOfHighNode.push_back(*node);
      }
   }
   double sum = 0;
   for(auto one = setOfHighNode.begin(); one != setOfHighNode.end(); one++)
   {
      for(auto two = one + 1; two != setOfHighNode.end(); two++)
      {
	 if(graph->HasEdge(*one, *two))
	    sum++;
      }
   }
   return 2 * sum / static_cast<double>(setOfHighNode.size() * (setOfHighNode.size() - 1));
}
 void IndexArrayMapBuilder::addPolygon(const IndexList& indices) {
     const size_t count = indices.size();
     
     IndexList polyIndices(0);
     polyIndices.reserve(3 * (count - 2));
     
     for (size_t i = 0; i < count - 2; ++i) {
         polyIndices.push_back(indices[0]);
         polyIndices.push_back(indices[i + 1]);
         polyIndices.push_back(indices[i + 2]);
     }
     
     add(GL_TRIANGLES, polyIndices);
 }
// Add triangle strip to the group
void GLC_PrimitiveGroup::addTrianglesStrip(const IndexList& input, GLC_uint id)
{
	m_StripsIndex+= input;
	m_TrianglesStripSize= m_StripsIndex.size();

	m_StripIndexSizes.append(static_cast<GLsizei>(input.size()));

	if (m_StripIndexOffseti.isEmpty())
	{
		m_StripIndexOffseti.append(0);
	}
	int offset= m_StripIndexOffseti.last() + m_StripIndexSizes.last();
	m_StripIndexOffseti.append(offset);

	// The strip id
	if (0 != id) m_StripsId.append(id);
	else Q_ASSERT(m_StripsId.isEmpty());
}
Example #13
0
void Sky::Subdivide(std::vector<D3DXVECTOR3>& vertices, std::vector<DWORD>& indices)
{
	VertexList vin = vertices;
	IndexList  iin = indices;

	vertices.resize(0);
	indices.resize(0);

	UINT numTris = (UINT)iin.size()/3;
	for(UINT i = 0; i < numTris; ++i)
	{
		D3DXVECTOR3 v0 = vin[ iin[i*3+0] ];
		D3DXVECTOR3 v1 = vin[ iin[i*3+1] ];
		D3DXVECTOR3 v2 = vin[ iin[i*3+2] ];

		D3DXVECTOR3 m0 = 0.5f*(v0 + v1);
		D3DXVECTOR3 m1 = 0.5f*(v1 + v2);
		D3DXVECTOR3 m2 = 0.5f*(v0 + v2);

		vertices.push_back(v0); // 0
		vertices.push_back(v1); // 1
		vertices.push_back(v2); // 2
		vertices.push_back(m0); // 3
		vertices.push_back(m1); // 4
		vertices.push_back(m2); // 5
 
		indices.push_back(i*6+0);
		indices.push_back(i*6+3);
		indices.push_back(i*6+5);

		indices.push_back(i*6+3);
		indices.push_back(i*6+4);
		indices.push_back(i*6+5);

		indices.push_back(i*6+5);
		indices.push_back(i*6+4);
		indices.push_back(i*6+2);

		indices.push_back(i*6+3);
		indices.push_back(i*6+1);
		indices.push_back(i*6+4);
	}
}
Example #14
0
// Add triangles Fan
GLC_uint GLC_Mesh::addTrianglesFan(GLC_Material* pMaterial, const IndexList& indexList, const int lod, double accuracy)
{
	GLC_uint groupId= setCurrentMaterial(pMaterial, lod, accuracy);
	Q_ASSERT(m_PrimitiveGroups.value(lod)->contains(groupId));
	Q_ASSERT(!indexList.isEmpty());

	GLC_uint id= 0;
	if (0 == lod)
	{
		id= m_NextPrimitiveLocalId++;
	}
	m_MeshData.trianglesAdded(lod, indexList.size() - 2);
	m_PrimitiveGroups.value(lod)->value(groupId)->addTrianglesFan(indexList, id);

	// Invalid the geometry
	m_GeometryIsValid = false;

	return id;
}
void process_for_equations(Modelica::MMO_Class &mmo_class) {
  EquationList &equations = mmo_class.equations_ref().equations_ref();
  EquationList new_equations;
  foreach_ (Equation &e, equations) {
    if (is<ForEq>(e)) {
      ForEq feq = boost::get<ForEq>(e);
      IndexList il = feq.range().indexes();
      ERROR_UNLESS(il.size() == 1,
          "process_for_equations:\n"
          "forIndexList with more than 1 forIndex are not supported yet\n");
      Index in = il.front();
      Name variable  = in.name();
      OptExp ind = in.exp();
      ERROR_UNLESS(ind, "for-equation's index with implicit range not supported yet\n");
      Expression exp = ind.get();
      ForIndexIterator *forIndexIter = NULL;
      if (is<Range>(exp)) {
        forIndexIter = new RangeIterator(get<Range>(exp),mmo_class.syms_ref());
      } else if (is<Brace>(exp)) {
        forIndexIter = new BraceIterator(get<Brace>(exp),mmo_class.syms_ref());
      } else {
        ERROR("For Iterator not supported");
      }
      while (forIndexIter->hasNext()) {
        Real index_val = forIndexIter->next();
        foreach_ (Equation eq, feq.elements()) 
          new_equations.push_back(instantiate_equation(eq, variable, index_val, mmo_class.syms_ref()));
      }
      delete forIndexIter;
    } else {
      // Not a for eq
      new_equations.push_back(e);
    }

  }
  mmo_class.equations_ref().equations_ref()=new_equations;
}
Example #16
0
void TriStripVisitor::stripify(Geometry& geom)
{
    if (geom.containsDeprecatedData()) geom.fixDeprecatedData();

    if (osg::getBinding(geom.getNormalArray())==osg::Array::BIND_PER_PRIMITIVE_SET) return;

    if (osg::getBinding(geom.getColorArray())==osg::Array::BIND_PER_PRIMITIVE_SET) return;

    if (osg::getBinding(geom.getSecondaryColorArray())==osg::Array::BIND_PER_PRIMITIVE_SET) return;

    if (osg::getBinding(geom.getFogCoordArray())==osg::Array::BIND_PER_PRIMITIVE_SET) return;

    // no point tri stripping if we don't have enough vertices.
    if (!geom.getVertexArray() || geom.getVertexArray()->getNumElements()<3) return;

    // check for the existence of surface primitives
    unsigned int numSurfacePrimitives = 0;
    unsigned int numNonSurfacePrimitives = 0;
    Geometry::PrimitiveSetList& primitives = geom.getPrimitiveSetList();
    Geometry::PrimitiveSetList::iterator itr;
    for(itr=primitives.begin();
        itr!=primitives.end();
        ++itr)
    {
        switch((*itr)->getMode())
        {
            case(PrimitiveSet::TRIANGLES):
            case(PrimitiveSet::TRIANGLE_STRIP):
            case(PrimitiveSet::TRIANGLE_FAN):
            case(PrimitiveSet::QUADS):
            case(PrimitiveSet::QUAD_STRIP):
            case(PrimitiveSet::POLYGON):
                ++numSurfacePrimitives;
                break;
            default:
                ++numNonSurfacePrimitives;
                break;

        }
    }

    // nothitng to tri strip leave.
    if (!numSurfacePrimitives) return;

    // compute duplicate vertices

    typedef std::vector<unsigned int> IndexList;
    unsigned int numVertices = geom.getVertexArray()->getNumElements();
    IndexList indices(numVertices);
    unsigned int i,j;
    for(i=0;i<numVertices;++i)
    {
        indices[i] = i;
    }

    VertexAttribComparitor arrayComparitor(geom);
    std::sort(indices.begin(),indices.end(),arrayComparitor);

    unsigned int lastUnique = 0;
    unsigned int numUnique = 1;
    unsigned int numDuplicate = 0;
    for(i=1;i<numVertices;++i)
    {
        if (arrayComparitor.compare(indices[lastUnique],indices[i])==0)
        {
            //std::cout<<"  found duplicate "<<indices[lastUnique]<<" and "<<indices[i]<<std::endl;
            ++numDuplicate;
        }
        else
        {
            //std::cout<<"  unique "<<indices[i]<<std::endl;
            lastUnique = i;
            ++numUnique;
        }

    }
//     std::cout<<"  Number of duplicates "<<numDuplicate<<std::endl;
//     std::cout<<"  Number of unique "<<numUnique<<std::endl;
//     std::cout<<"  Total number of vertices required "<<numUnique<<" vs original "<<numVertices<<std::endl;
//     std::cout<<"  % size "<<(float)numUnique/(float)numVertices*100.0f<<std::endl;

    IndexList remapDuplicatesToOrignals(numVertices);
    lastUnique = 0;
    for(i=1;i<numVertices;++i)
    {
        if (arrayComparitor.compare(indices[lastUnique],indices[i])!=0)
        {
            // found a new vertex entry, so previous run of duplicates needs
            // to be put together.
            unsigned int min_index = indices[lastUnique];
            for(j=lastUnique+1;j<i;++j)
            {
                min_index = osg::minimum(min_index,indices[j]);
            }
            for(j=lastUnique;j<i;++j)
            {
                remapDuplicatesToOrignals[indices[j]]=min_index;
            }
            lastUnique = i;
        }

    }
    unsigned int min_index = indices[lastUnique];
    for(j=lastUnique+1;j<i;++j)
    {
        min_index = osg::minimum(min_index,indices[j]);
    }
    for(j=lastUnique;j<i;++j)
    {
        remapDuplicatesToOrignals[indices[j]]=min_index;
    }


    // copy the arrays.
    IndexList finalMapping(numVertices);
    IndexList copyMapping;
    copyMapping.reserve(numUnique);
    unsigned int currentIndex=0;
    for(i=0;i<numVertices;++i)
    {
        if (remapDuplicatesToOrignals[i]==i)
        {
            finalMapping[i] = currentIndex;
            copyMapping.push_back(i);
            currentIndex++;
        }
    }

    for(i=0;i<numVertices;++i)
    {
        if (remapDuplicatesToOrignals[i]!=i)
        {
            finalMapping[i] = finalMapping[remapDuplicatesToOrignals[i]];
        }
    }


    MyTriangleIndexFunctor taf;
    taf._remapIndices.swap(finalMapping);

    Geometry::PrimitiveSetList new_primitives;
    new_primitives.reserve(primitives.size());

    for(itr=primitives.begin();
        itr!=primitives.end();
        ++itr)
    {
        switch((*itr)->getMode())
        {
            case(PrimitiveSet::TRIANGLES):
            case(PrimitiveSet::TRIANGLE_STRIP):
            case(PrimitiveSet::TRIANGLE_FAN):
            case(PrimitiveSet::QUADS):
            case(PrimitiveSet::QUAD_STRIP):
            case(PrimitiveSet::POLYGON):
                (*itr)->accept(taf);
                break;
            default:
                new_primitives.push_back(*itr);
                break;

        }
    }

    float minimum_ratio_of_indices_to_unique_vertices = 1;
    float ratio_of_indices_to_unique_vertices = ((float)taf._in_indices.size()/(float)numUnique);

    OSG_INFO<<"TriStripVisitor::stripify(Geometry&): Number of indices"<<taf._in_indices.size()<<" numUnique"<< numUnique << std::endl;
    OSG_INFO<<"TriStripVisitor::stripify(Geometry&):     ratio indices/numUnique"<< ratio_of_indices_to_unique_vertices << std::endl;

    // only tri strip if there is point in doing so.
    if (!taf._in_indices.empty() && ratio_of_indices_to_unique_vertices>=minimum_ratio_of_indices_to_unique_vertices)
    {
        OSG_INFO<<"TriStripVisitor::stripify(Geometry&):     doing tri strip"<< std::endl;

        unsigned int in_numVertices = 0;
        for(triangle_stripper::indices::iterator itr=taf._in_indices.begin();
            itr!=taf._in_indices.end();
            ++itr)
        {
            if (*itr>in_numVertices) in_numVertices=*itr;
        }
        // the largest indice is in_numVertices, but indices start at 0
        // so increment to give to the corrent number of verticies.
        ++in_numVertices;

        // remap any shared vertex attributes
        RemapArray ra(copyMapping);
        arrayComparitor.accept(ra);

        triangle_stripper::tri_stripper stripifier(taf._in_indices);
        stripifier.SetCacheSize(_cacheSize);
        stripifier.SetMinStripSize(_minStripSize);

        triangle_stripper::primitive_vector outPrimitives;
        stripifier.Strip(&outPrimitives);
        if (outPrimitives.empty())
        {
            OSG_WARN<<"Error: TriStripVisitor::stripify(Geometry& geom) failed."<<std::endl;
            return;
        }

        triangle_stripper::primitive_vector::iterator pitr;
        if (_generateFourPointPrimitivesQuads)
        {
            OSG_INFO<<"Collecting all quads"<<std::endl;

            typedef triangle_stripper::primitive_vector::iterator prim_iterator;
            typedef std::multimap<unsigned int,prim_iterator> QuadMap;
            QuadMap quadMap;

            // pick out quads and place them in the quadMap, and also look for the max
            for(pitr=outPrimitives.begin();
                pitr!=outPrimitives.end();
                ++pitr)
            {
                if (pitr->Indices.size()==4)
                {
                    std::swap(pitr->Indices[2],pitr->Indices[3]);
                    unsigned int minValue = *(std::max_element(pitr->Indices.begin(),pitr->Indices.end()));
                    quadMap.insert(QuadMap::value_type(minValue,pitr));
                }
            }


            // handle the quads
            if (!quadMap.empty())
            {
                IndexList indices;
                indices.reserve(4*quadMap.size());

                // adds all the quads into the quad primitive, in ascending order
                // and the QuadMap stores the quad's in ascending order.
                for(QuadMap::iterator qitr=quadMap.begin();
                    qitr!=quadMap.end();
                    ++qitr)
                {
                    pitr = qitr->second;

                    unsigned int min_pos = 0;
                    for(i=1;i<4;++i)
                    {
                        if (pitr->Indices[min_pos]>pitr->Indices[i])
                            min_pos = i;
                    }
                    indices.push_back(pitr->Indices[min_pos]);
                    indices.push_back(pitr->Indices[(min_pos+1)%4]);
                    indices.push_back(pitr->Indices[(min_pos+2)%4]);
                    indices.push_back(pitr->Indices[(min_pos+3)%4]);
                }

                bool inOrder = true;
                unsigned int previousValue = indices.front();
                for(IndexList::iterator qi_itr=indices.begin()+1;
                    qi_itr!=indices.end() && inOrder;
                    ++qi_itr)
                {
                    inOrder = (previousValue+1)==*qi_itr;
                    previousValue = *qi_itr;
                }


                if (inOrder)
                {
                    new_primitives.push_back(new osg::DrawArrays(GL_QUADS,indices.front(),indices.size()));
                }
                else
                {
                    unsigned int maxValue = *(std::max_element(indices.begin(),indices.end()));

                    if (maxValue>=65536)
                    {
                        osg::DrawElementsUInt* elements = new osg::DrawElementsUInt(GL_QUADS);
                        std::copy(indices.begin(),indices.end(),std::back_inserter(*elements));
                        new_primitives.push_back(elements);
                    }
                    else
                    {
                        osg::DrawElementsUShort* elements = new osg::DrawElementsUShort(GL_QUADS);
                        std::copy(indices.begin(),indices.end(),std::back_inserter(*elements));
                        new_primitives.push_back(elements);
                    }
                }
            }
        }

        // handle non quad primitives
        for(pitr=outPrimitives.begin();
            pitr!=outPrimitives.end();
            ++pitr)
        {
            if (!_generateFourPointPrimitivesQuads || pitr->Indices.size()!=4)
            {
                bool inOrder = true;
                unsigned int previousValue = pitr->Indices.front();
                for(triangle_stripper::indices::iterator qi_itr=pitr->Indices.begin()+1;
                    qi_itr!=pitr->Indices.end() && inOrder;
                    ++qi_itr)
                {
                    inOrder = (previousValue+1)==*qi_itr;
                    previousValue = *qi_itr;
                }

                if (inOrder)
                {
                    new_primitives.push_back(new osg::DrawArrays(pitr->Type,pitr->Indices.front(),pitr->Indices.size()));
                }
                else
                {
                    unsigned int maxValue = *(std::max_element(pitr->Indices.begin(),pitr->Indices.end()));
                    if (maxValue>=65536)
                    {
                        osg::DrawElementsUInt* elements = new osg::DrawElementsUInt(pitr->Type);
                        elements->reserve(pitr->Indices.size());
                        std::copy(pitr->Indices.begin(),pitr->Indices.end(),std::back_inserter(*elements));
                        new_primitives.push_back(elements);
                    }
                    else
                    {
                        osg::DrawElementsUShort* elements = new osg::DrawElementsUShort(pitr->Type);
                        elements->reserve(pitr->Indices.size());
                        std::copy(pitr->Indices.begin(),pitr->Indices.end(),std::back_inserter(*elements));
                        new_primitives.push_back(elements);
                    }
                }
            }
        }

        geom.setPrimitiveSetList(new_primitives);

        #if 0
        // debugging code for indentifying the tri-strips.
                osg::Vec4Array* colors = new osg::Vec4Array(new_primitives.size());
                for(i=0;i<colors->size();++i)
                {
                    (*colors)[i].set(((float)rand()/(float)RAND_MAX),
                                     ((float)rand()/(float)RAND_MAX),
                                     ((float)rand()/(float)RAND_MAX),
                                     1.0f);
                }
                geom.setColorArray(colors);
                geom.setColorBinding(osg::Array::BIND_PER_PRIMITIVE_SET);
        #endif
    }
    else
    {
        OSG_INFO<<"TriStripVisitor::stripify(Geometry&):     not doing tri strip *****************"<< std::endl;
    }

}
Example #17
0
void OutBuilding::build(float w, float h, float d){
	VertexPNTList vertices;
	VertexPNT v;
	float width = w;
	float height = h;
	float depth = d;
	float thrirdwidth = w/3;
	float twothirdwidth = (2*w)/3;
	float twothirdheight = (2*h)/3;
	//Front
	v.normal = D3DXVECTOR3( 0.0f,  0.0f, -1.0f);
	v.pos = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
	v.texC = D3DXVECTOR2(0.0,0.0);
	vertices.push_back(v);
	v.pos = D3DXVECTOR3(0.0f, height, 0.0f);
	v.texC = D3DXVECTOR2(0.0,1.0);
	vertices.push_back(v);
	v.pos = D3DXVECTOR3(thrirdwidth, height, 0.0f);
	v.texC = D3DXVECTOR2(0.4,1.0);
	vertices.push_back(v);
	v.pos = D3DXVECTOR3(thrirdwidth, 0.0f, 0.0f);
	v.texC = D3DXVECTOR2(0.4,0.0);
	vertices.push_back(v);

	v.pos = D3DXVECTOR3(thrirdwidth, twothirdheight, 0.0f);
	v.texC = D3DXVECTOR2(0.4,0.7);
	vertices.push_back(v);
	v.pos = D3DXVECTOR3(twothirdwidth, twothirdheight, 0.0f);
	v.texC = D3DXVECTOR2(0.8,0.7);
	vertices.push_back(v);

	v.pos = D3DXVECTOR3(twothirdwidth, height, 0.0f);
	v.texC = D3DXVECTOR2(0.8,1.0);
	vertices.push_back(v);
	v.pos = D3DXVECTOR3(width, height, 0.0f);
	v.texC = D3DXVECTOR2(1.0,1.0);
	vertices.push_back(v);
	v.pos = D3DXVECTOR3(width, 0.0f, 0.0f);
	v.texC = D3DXVECTOR2(1.0,0.0);
	vertices.push_back(v);
	v.pos = D3DXVECTOR3(twothirdwidth, 0.0f, 0.0f);
	v.texC = D3DXVECTOR2(0.8,0.0);
	vertices.push_back(v);

	//Left Face
	v.normal = D3DXVECTOR3( -1.0f,  0.0f, 0.0f);
	v.pos = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
	v.texC = D3DXVECTOR2(0.0,0.0);
	vertices.push_back(v);
	v.pos = D3DXVECTOR3(0.0f, height, 0.0f);
	v.texC = D3DXVECTOR2(0.0,1.0);
	vertices.push_back(v);
	v.pos = D3DXVECTOR3(0.0f, height, depth);
	v.texC = D3DXVECTOR2(1.0,1.0);
	vertices.push_back(v);
	v.pos = D3DXVECTOR3(0.0f, 0.0f, depth);
	v.texC = D3DXVECTOR2(1.0,0.0);
	vertices.push_back(v);

	//Top
	v.normal = D3DXVECTOR3( 0.0f,  1.0f, 0.0f);
	v.pos = D3DXVECTOR3(0.0f, height, 0.0f);
	v.texC = D3DXVECTOR2(0.0,0.0);
	vertices.push_back(v);
	v.pos = D3DXVECTOR3(0.0f, height, depth);
	v.texC = D3DXVECTOR2(0.0,1.0);
	vertices.push_back(v);
	v.pos = D3DXVECTOR3(width, height, depth);
	v.texC = D3DXVECTOR2(1.0,1.0);
	vertices.push_back(v);
	v.pos = D3DXVECTOR3(width, height, 0.0f);
	v.texC = D3DXVECTOR2(1.0,0.0);
	vertices.push_back(v);

	//Right
	v.normal = D3DXVECTOR3( 1.0f,  0.0f, 0.0f);
	v.pos = D3DXVECTOR3(width, 0.0f, 0.0f);
	v.texC = D3DXVECTOR2(0.0,0.0);
	vertices.push_back(v);
	v.pos = D3DXVECTOR3(width, 0.0f, depth);
	v.texC = D3DXVECTOR2(0.0,1.0);
	vertices.push_back(v);
	v.pos = D3DXVECTOR3(width, height, depth);
	v.texC = D3DXVECTOR2(1.0,1.0);
	vertices.push_back(v);
	v.pos = D3DXVECTOR3(width, height, 0.0f);
	v.texC = D3DXVECTOR2(1.0,0.0);
	vertices.push_back(v);

	//Bottom
	v.normal = D3DXVECTOR3( 0.0f,  -1.0f, 0.0f);
	v.pos = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
	v.texC = D3DXVECTOR2(0.0,0.0);
	vertices.push_back(v);
	v.pos = D3DXVECTOR3(0.0f, 0.0f, depth);
	v.texC = D3DXVECTOR2(0.0,1.0);
	vertices.push_back(v);
	v.pos = D3DXVECTOR3(width, 0.0f, depth);
	v.texC = D3DXVECTOR2(1.0,1.0);
	vertices.push_back(v);
	v.pos = D3DXVECTOR3(width, 0.0f, 0.0f);
	v.texC = D3DXVECTOR2(1.0,0.0);
	vertices.push_back(v);

	//Back
	v.normal = D3DXVECTOR3( 0.0f,  0.0f, 1.0f);
	v.pos = D3DXVECTOR3(width, 0.0f, depth);
	v.texC = D3DXVECTOR2(0.0,0.0);
	vertices.push_back(v);
	v.pos = D3DXVECTOR3(width, height, depth);
	v.texC = D3DXVECTOR2(0.0,1.0);
	vertices.push_back(v);
	v.pos = D3DXVECTOR3(0.0f, height, depth);
	v.texC = D3DXVECTOR2(1.0,1.0);
	vertices.push_back(v);
	v.pos = D3DXVECTOR3(0.0f, 0.0f, depth);
	v.texC = D3DXVECTOR2(1.0,0.0);
	vertices.push_back(v);

	mNumVertices = (UINT)vertices.size();
	buildVB(vertices);

	IndexList indices;

	indices.push_back(0);
	indices.push_back(1);
	indices.push_back(2);
	indices.push_back(2);
	indices.push_back(3);
	indices.push_back(0);

	indices.push_back(4);
	indices.push_back(2);
	indices.push_back(6);
	indices.push_back(6);
	indices.push_back(5);
	indices.push_back(4);

	indices.push_back(9);
	indices.push_back(6);
	indices.push_back(7);
	indices.push_back(7);
	indices.push_back(8);
	indices.push_back(9);

	indices.push_back(10);
	indices.push_back(13);
	indices.push_back(12);
	indices.push_back(12);
	indices.push_back(11);
	indices.push_back(10);

	indices.push_back(14);
	indices.push_back(15);
	indices.push_back(16);
	indices.push_back(16);
	indices.push_back(17);
	indices.push_back(14);

	indices.push_back(18);
	indices.push_back(21);
	indices.push_back(16);
	indices.push_back(16);
	indices.push_back(19);
	indices.push_back(18);

	indices.push_back(22);
	indices.push_back(25);
	indices.push_back(24);
	indices.push_back(24);
	indices.push_back(23);
	indices.push_back(22);

	indices.push_back(26);
	indices.push_back(27);
	indices.push_back(28);
	indices.push_back(28);
	indices.push_back(29);
	indices.push_back(26);

	mNumFaces    = (UINT)indices.size()/3;
	mNumIndices  = (UINT)indices.size();
	buildIB(indices);
}
void test(bool indexed)
{
    if (os_) *os_ << "test(): indexed=\"" << boolalpha << indexed << "\"\n";

    MSData tiny;
    examples::initializeTiny(tiny);

    Serializer_mzML::Config config;
    config.indexed = indexed;
    Serializer_mzML serializer(config);  

    ostringstream oss;
    serializer.write(oss, tiny);

    if (os_) *os_ << "oss:\n" << oss.str() << endl;

    shared_ptr<istream> is(new istringstream(oss.str()));

    // dummy would normally be read in from file
  
    MSData dummy;

    ParamGroupPtr pg1(new ParamGroup);
    pg1->id = "CommonMS1SpectrumParams";
    pg1->cvParams.push_back(MS_positive_scan);
    pg1->cvParams.push_back(MS_full_scan);
    dummy.paramGroupPtrs.push_back(pg1);

    ParamGroupPtr pg2(new ParamGroup);
    pg2->id = "CommonMS2SpectrumParams";
    pg2->cvParams.push_back(MS_positive_scan);
    pg2->cvParams.push_back(MS_full_scan);
    dummy.paramGroupPtrs.push_back(pg2);

    // so we don't have any dangling references
    dummy.instrumentConfigurationPtrs.push_back(InstrumentConfigurationPtr(new InstrumentConfiguration("LCQDeca")));
    dummy.dataProcessingPtrs.push_back(DataProcessingPtr(new DataProcessing("XcaliburProcessing")));

    SpectrumListPtr sl = SpectrumList_mzML::create(is, dummy, indexed);

    // check easy functions

    unit_assert(sl.get());
    unit_assert(sl->size() == 4);
    unit_assert(sl->find ("S19") == 0);
    unit_assert(sl->findNative("19") == 0);
    unit_assert(sl->find("S20") == 1);
    unit_assert(sl->findNative("20") == 1);
    unit_assert(sl->find("S21") == 2);
    unit_assert(sl->findNative("21") == 2);
    unit_assert(sl->find("S22") == 3);
    unit_assert(sl->findNative("22") == 3);

    unit_assert(sl->findSpotID("A1").empty());
    IndexList spotIndexList = sl->findSpotID("A1,42x42,4242x4242");
    unit_assert(spotIndexList.size() == 1);
    unit_assert(spotIndexList[0] == 3);


    // check scan 19

    SpectrumPtr s = sl->spectrum(0); // read without binary data
    unit_assert(s.get());
    unit_assert(s->id == "S19");
    unit_assert(s->nativeID == "19");
    unit_assert(s->spotID.empty());
    unit_assert(s->cvParam(MS_ms_level).valueAs<int>() == 1);
    unit_assert(s->binaryDataArrayPtrs.empty());

    unit_assert(sl->spectrumIdentity(0).index == 0);
    unit_assert(sl->spectrumIdentity(0).id == "S19");
    unit_assert(sl->spectrumIdentity(0).nativeID == "19");
    unit_assert(sl->spectrumIdentity(0).spotID.empty());
 
    SpectrumPtr s_cache = sl->spectrum(0); // cache read
    unit_assert(s_cache.get() == s.get());

    s = sl->spectrum(0, true); // read with binary data
    unit_assert(s_cache.get() != s.get());

    vector<MZIntensityPair> pairs;
    s->getMZIntensityPairs(pairs);
    unit_assert(pairs.size() == 15);
    for (int i=0; i<15; i++)
        unit_assert(pairs[i].mz==i && pairs[i].intensity==15-i);

    unit_assert(s->spectrumDescription.scan.paramGroupPtrs.size() == 1);
    unit_assert(s->spectrumDescription.scan.paramGroupPtrs.back()->id == "CommonMS1SpectrumParams");
    unit_assert(s->spectrumDescription.scan.paramGroupPtrs.back()->cvParams.size() == 2);

    // check scan 20

    s = sl->spectrum(1, true);
    unit_assert(s.get());
    unit_assert(s->id == "S20");
    unit_assert(s->nativeID == "20");
    unit_assert(s->spotID.empty());
    unit_assert(s->cvParam(MS_ms_level).valueAs<int>() == 2);

    unit_assert(sl->spectrumIdentity(1).index == 1);
    unit_assert(sl->spectrumIdentity(1).id == "S20");
    unit_assert(sl->spectrumIdentity(1).nativeID == "20");
    unit_assert(sl->spectrumIdentity(1).spotID.empty());

    pairs.clear();
    s->getMZIntensityPairs(pairs);
    unit_assert(pairs.size() == 10);
    for (int i=0; i<10; i++)
        unit_assert(pairs[i].mz==2*i && pairs[i].intensity==(10-i)*2);

    unit_assert(s->spectrumDescription.scan.paramGroupPtrs.size() == 1);
    unit_assert(s->spectrumDescription.scan.paramGroupPtrs.back()->id == "CommonMS2SpectrumParams");
    unit_assert(s->spectrumDescription.scan.paramGroupPtrs.back()->cvParams.size() == 2);

    // check scan 22 (MALDI)
    s = sl->spectrum(3, true);
    unit_assert(s.get());
    unit_assert(s->id == "S22");
    unit_assert(s->nativeID == "22");
    unit_assert(s->spotID == "A1,42x42,4242x4242");
    unit_assert(s->cvParam(MS_ms_level).valueAs<int>() == 1);

    unit_assert(sl->spectrumIdentity(3).index == 3);
    unit_assert(sl->spectrumIdentity(3).id == "S22");
    unit_assert(sl->spectrumIdentity(3).nativeID == "22");
    unit_assert(sl->spectrumIdentity(3).spotID == "A1,42x42,4242x4242");
}
 void IndexArrayMapBuilder::add(const PrimType primType, const IndexList& indices) {
     const size_t offset = m_ranges.add(primType, indices.size());
     IndexList::iterator dest = m_indices.begin();
     std::advance(dest, offset);
     std::copy(indices.begin(), indices.end(), dest);
 }
 void IndexArrayMapBuilder::addQuads(const IndexList& indices) {
     assert(indices.size() % 4 == 0);
     add(GL_QUADS, indices);
 }
 void IndexArrayMapBuilder::addTriangles(const IndexList& indices) {
     assert(indices.size() % 3 == 0);
     add(GL_TRIANGLES, indices);
 }
 void IndexArrayMapBuilder::addLines(const IndexList& indices) {
     assert(indices.size() % 2 == 0);
     add(GL_LINES, indices);
 }