Exemple #1
0
 /**
  * Generate indices that would sort this vector in ascending order
  * @param indx :: STD vector to output the sorting indices.
  */
 void GSLVector::indexSort(std::vector<size_t>& indx)
 {
   indx.resize( size() );
   for(size_t i = 0; i < indx.size(); ++i)
   {
     indx[i] = i;
   }
   std::sort(indx.begin(),indx.end(),SortAscending(*this));
 }
Exemple #2
0
void Jacobi(const SymmetricMatrix& X, DiagonalMatrix& D, SymmetricMatrix& A,
   Matrix& V, bool eivec)
{
   Real epsilon = FloatingPointPrecision::Epsilon();
   Tracer et("Jacobi");
   REPORT
   int n = X.Nrows(); DiagonalMatrix B(n), Z(n); D.resize(n); A = X;
   if (eivec) { REPORT V.resize(n,n); D = 1.0; V = D; }
   B << A; D = B; Z = 0.0; A.Inject(Z);
   bool converged = false;
   for (int i=1; i<=50; i++)
   {
      Real sm=0.0; Real* a = A.Store(); int p = A.Storage();
      while (p--) sm += fabs(*a++);            // have previously zeroed diags
      if (sm==0.0) { REPORT converged = true; break; }
      Real tresh = (i<4) ? 0.2 * sm / square(n) : 0.0; a = A.Store();
      for (p = 0; p < n; p++)
      {
         Real* ap1 = a + (p*(p+1))/2;
         Real& zp = Z.element(p); Real& dp = D.element(p);
         for (int q = p+1; q < n; q++)
         {
            Real* ap = ap1; Real* aq = a + (q*(q+1))/2;
            Real& zq = Z.element(q); Real& dq = D.element(q);
            Real& apq = A.element(q,p);
            Real g = 100 * fabs(apq); Real adp = fabs(dp); Real adq = fabs(dq);

            if (i>4 && g < epsilon*adp && g < epsilon*adq) { REPORT apq = 0.0; }
            else if (fabs(apq) > tresh)
            {
               REPORT
               Real t; Real h = dq - dp; Real ah = fabs(h);
               if (g < epsilon*ah) { REPORT t = apq / h; }
               else
               {
                  REPORT
                  Real theta = 0.5 * h / apq;
                  t = 1.0 / ( fabs(theta) + sqrt(1.0 + square(theta)) );
                  if (theta<0.0) { REPORT t = -t; }
               }
               Real c = 1.0 / sqrt(1.0 + square(t)); Real s = t * c;
               Real tau = s / (1.0 + c); h = t * apq;
               zp -= h; zq += h; dp -= h; dq += h; apq = 0.0;
               int j = p;
               while (j--)
               {
                  g = *ap; h = *aq;
                  *ap++ = g-s*(h+g*tau); *aq++ = h+s*(g-h*tau);
               }
               int ip = p+1; j = q-ip; ap += ip++; aq++;
               while (j--)
               {
                  g = *ap; h = *aq;
                  *ap = g-s*(h+g*tau); *aq++ = h+s*(g-h*tau);
                  ap += ip++;
               }
               if (q < n-1)             // last loop is non-empty
               {
                  int iq = q+1; j = n-iq; ap += ip++; aq += iq++;
                  for (;;)
                  {
                     g = *ap; h = *aq;
                     *ap = g-s*(h+g*tau); *aq = h+s*(g-h*tau);
                     if (!(--j)) break;
                     ap += ip++; aq += iq++;
                  }
               }
               if (eivec)
               {
                  REPORT
                  RectMatrixCol VP(V,p); RectMatrixCol VQ(V,q);
                  Rotate(VP, VQ, tau, s);
               }
            }
         }
      }
      B = B + Z; D = B; Z = 0.0;
   }
   if (!converged) Throw(ConvergenceException(X));
   if (eivec) SortSV(D, V, true);
   else SortAscending(D);
}
void BaseCaller::MakeCall( Trace& Tr, SimpleMatrix<int>& Peak, int nPos, int nAmbiguityWindow )
{
    assert(nPos>=0);
    assert(nAmbiguityWindow>0);
    call_t Signal[4];


    // Initialisation
    Init();
    // m_nPosition[2] = nPos; jkb 25/06/2003. What should this be?


    // Search for peaks and load them in
    int peaks = LoadPeaks( Peak, nPos, nAmbiguityWindow, Signal );


    // Find biggest peaks position
    if( peaks > 0 )
    {
        int max_sig = 0;
        int max_amp = -1;
        for( int n=3; n>=0; n-- )
        {
            if( Signal[n].Position >= 0 )
            {
                if( Signal[n].Amplitude > max_amp )
                {
                    max_sig = n;
                    max_amp = Signal[n].Amplitude;
                }
            }
        }
        nPos = Signal[max_sig].Position;
    }


    // Load trace amplitudes for peakless bases
    for( int n=0; n<4; n++ )
    {
        if( Signal[n].Position < 0 )
            Signal[n].Amplitude = Tr[n][nPos];
    }


    // Sort the entire lot by amplitude
    SortAscending( Signal );


    // Basecall single peak
    DNATable Table;
    if( peaks == 1 )
    {

        for( int n=3; n>=0; n-- )
        {
            if( Signal[n].Position >= 0 )
            {
                m_nCall[0]      = Table.LookupBase( Signal[n].Index );
                m_nCall[1]      = m_nCall[0];
                m_nPosition[0]  = Signal[n].Position;
                m_nAmplitude[0] = Signal[n].Amplitude;
            }
        }
    }


    // Basecall multiple peaks
    else if( peaks >= 2 )
    {
        call_t highest_signal;
        int    highest_signal_n;
        highest_signal.Index = -1;
        for( int n=3; n>=0; n-- )
        {
            if( Signal[n].Position >= 0 )
            {
                if( highest_signal.Index < 0 )
                {
                    highest_signal   = Signal[n];
                    highest_signal_n = n;
                }
                else
                {
                    m_nCall[0]      = Table.LookupBase( highest_signal.Index, Signal[n].Index );
                    m_nCall[1]      = Table.LookupBase( highest_signal.Index );
                    m_nCall[2]      = Table.LookupBase( Signal[n].Index );
                    m_nPosition[0]  = highest_signal.Position;
                    m_nAmplitude[0] = highest_signal.Amplitude;
                    m_nPosition[1]  = Signal[n].Position;
                    m_nAmplitude[1] = Signal[n].Amplitude;
                }
            }
        }
    }


    // Compute confidence value, just SNR(db) = 20*log(S/N)
    double S = Signal[3].Amplitude;
    double N = Signal[2].Amplitude;
    if( N <= 0.0 )
        N = 1.0;
    m_nPeakRatio  = S / N;
    m_nConfidence = m_nPeakRatio
      ? 20.0 * std::log10( m_nPeakRatio )
      : 0;
}
	//-----------------------------------------------------------------------
	void MeshInfo::getMeshInformation(	Ogre::MeshPtr mesh,
										const Vector3 &position,
										const Quaternion &orient,
										const Vector3 &scale)
	{
		size_t vertexCount = 0;
		size_t indexCount = 0;
		Vector3* vertices = 0;
		Vector3* normals;
		unsigned long* indices = 0;

		bool added_shared = false;
		size_t current_offset = 0;
		size_t shared_offset = 0;
		size_t next_offset = 0;
		size_t index_offset = 0;

		// Calculate how many vertices and indices we're going to need
		for ( unsigned short i = 0; i < mesh->getNumSubMeshes(); ++i)
		{
			Ogre::SubMesh* submesh = mesh->getSubMesh( i );

			// We only need to add the shared vertices once
			if(submesh->useSharedVertices)
			{
				if( !added_shared )
				{
					vertexCount += mesh->sharedVertexData->vertexCount;
					added_shared = true;
				}
			}
			else
			{
				vertexCount += submesh->vertexData->vertexCount;
			}

			// Add the indices
			indexCount += submesh->indexData->indexCount;
		}

		// Allocate space for the vertices and indices
		vertices = new Vector3[vertexCount];
		normals = new Vector3[vertexCount];
		indices = new unsigned long[indexCount];
		added_shared = false;

		// Run through the submeshes again, adding the data into the arrays
		for ( unsigned short i = 0; i < mesh->getNumSubMeshes(); ++i)
		{
			Ogre::SubMesh* submesh = mesh->getSubMesh(i);
			Ogre::VertexData* vertex_data = submesh->useSharedVertices ? mesh->sharedVertexData : submesh->vertexData;

			if((!submesh->useSharedVertices)||(submesh->useSharedVertices && !added_shared))
			{
				if(submesh->useSharedVertices)
				{
					added_shared = true;
					shared_offset = current_offset;
				}

				const Ogre::VertexElement* posElem = vertex_data->vertexDeclaration->findElementBySemantic(Ogre::VES_POSITION);
				const Ogre::VertexElement* normalElem = vertex_data->vertexDeclaration->findElementBySemantic(Ogre::VES_NORMAL);
				Ogre::HardwareVertexBufferSharedPtr vbuf = vertex_data->vertexBufferBinding->getBuffer(posElem->getSource());
				unsigned char* vertex = static_cast<unsigned char*>(vbuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));
				float* pReal;

				for( size_t j = 0; j < vertex_data->vertexCount; ++j, vertex += vbuf->getVertexSize())
				{
					posElem->baseVertexPointerToElement(vertex, &pReal);
					Vector3 pt(pReal[0], pReal[1], pReal[2]);
					vertices[current_offset + j] = (orient * (pt * scale)) + position;

					normalElem->baseVertexPointerToElement(vertex, &pReal);
					Vector3 nt(pReal[0], pReal[1], pReal[2]);
					normals[current_offset + j] = nt;
				}
      
				vbuf->unlock();
				next_offset += vertex_data->vertexCount;
			}

			Ogre::IndexData* index_data = submesh->indexData;
			size_t numTris = index_data->indexCount / 3;
			Ogre::HardwareIndexBufferSharedPtr ibuf = index_data->indexBuffer;
    		bool use32bitindexes = (ibuf->getType() == Ogre::HardwareIndexBuffer::IT_32BIT);
			unsigned long*  pLong = static_cast<unsigned long*>(ibuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));
			unsigned short* pShort = reinterpret_cast<unsigned short*>(pLong);
			size_t offset = (submesh->useSharedVertices)? shared_offset : current_offset;

			size_t numTrisMultThree = numTris*3;
			if ( use32bitindexes )
			{
				for ( size_t k = 0; k < numTrisMultThree; ++k)
				{
					indices[index_offset++] = pLong[k] + static_cast<unsigned long>(offset);
				}
			}
			else
			{
				for ( size_t k = 0; k < numTrisMultThree; ++k)
				{
					indices[index_offset++] = static_cast<unsigned long>(pShort[k]) + static_cast<unsigned long>(offset);
				}
			}

			ibuf->unlock();
			current_offset = next_offset;
		}

		// Create triangles from the retrieved data
		for (size_t k = 0; k < indexCount-1; k+=3)
		{
			Triangle t;
			t.v1 = vertices [indices[k]];
			t.vn1 = normals [indices[k]];

			t.v2 = vertices [indices[k+1]];
			t.vn2 = normals [indices[k+1]];

			t.v3 = vertices [indices[k+2]];
			t.vn3 = normals [indices[k+2]];

			t.calculateSquareSurface();
			t.calculateSurfaceNormal();
			t.calculateEdgeNormals();
			_triangles.push_back(t);
		}

		// Delete intermediate arrays
		delete [] indices;
		delete [] normals;
		delete [] vertices;

		// Sort the triangle on their size, if needed (only if a gaussian random number generator
		// function is used to perform a random lookup of a triangle)
		if (mDistribution == MSD_HOMOGENEOUS)
			sort(_triangles.begin(), _triangles.end(), SortDescending());
		else
			if (mDistribution == MSD_HETEROGENEOUS_1)
				sort(_triangles.begin(), _triangles.end(), SortAscending());
	}