Exemplo n.º 1
0
void Shape::Update()
{
    // Get the total number of points of the shape
    unsigned int count = GetPointCount();
    if (count < 3)
    {
        myVertices.Resize(0);
        myOutlineVertices.Resize(0);
        return;
    }

    myVertices.Resize(count + 2); // + 2 for center and repeated first point

    // Position
    for (unsigned int i = 0; i < count; ++i)
        myVertices[i + 1].Position = GetPoint(i);
    myVertices[count + 1].Position = myVertices[1].Position;

    // Update the bounding rectangle
    myVertices[0] = myVertices[1]; // so that the result of GetBounds() is correct
    myInsideBounds = myVertices.GetBounds();

    // Compute the center and make it the first vertex
    myVertices[0].Position.x = myInsideBounds.Left + myInsideBounds.Width / 2;
    myVertices[0].Position.y = myInsideBounds.Top + myInsideBounds.Height / 2;

    // Color
    UpdateFillColors();

    // Texture coordinates
    UpdateTexCoords();

    // Outline
    UpdateOutline();
}
Exemplo n.º 2
0
ManualObject* OgreNewtonMesh::CreateEntity (const String& name) const
{
	ManualObject* const object = new ManualObject(name);

	int pointCount = GetPointCount();
	int indexCount = GetTotalIndexCount();

	dNewtonScopeBuffer<int> indexList (indexCount);
	dNewtonScopeBuffer<int> remapIndex (indexCount);
	dNewtonScopeBuffer<dNewtonMesh::dPoint> posits (pointCount);
	dNewtonScopeBuffer<dNewtonMesh::dPoint> normals (pointCount);
	dNewtonScopeBuffer<dNewtonMesh::dUV> uv0 (pointCount);
	dNewtonScopeBuffer<dNewtonMesh::dUV> uv1 (pointCount);
	
	GetVertexStreams(&posits[0], &normals[0], &uv0[0], &uv1[0]);

	void* const materialsHandle = BeginMaterialHandle (); 
	for (int handle = GetMaterialIndex (materialsHandle); handle != -1; handle = GetNextMaterialIndex (materialsHandle, handle)) {
		int materialIndex = MaterialGetMaterial (materialsHandle, handle); 
		int indexCount = MaterialGetIndexCount (materialsHandle, handle); 
		MaterialGetIndexStream (materialsHandle, handle, &indexList[0]); 

		MaterialMap::const_iterator materialItr = m_materialMap.find(materialIndex);

		//object->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_LIST);
		object->begin(materialItr->second->getName(), Ogre::RenderOperation::OT_TRIANGLE_LIST);
		
		// ogre does not support shared vertex for sub mesh, we will have remap the vertex data
		int vertexCount = 0;
		memset (&remapIndex[0], 0xff, indexCount * sizeof (remapIndex[0]));
		for( int i = 0; i < indexCount; i ++) {
			int index = indexList[i];
			if (remapIndex[index] == -1) {
				remapIndex[index] = vertexCount;
				object->position (posits[index].m_x, posits[index].m_y, posits[index].m_z);
				object->normal (normals[index].m_x, normals[index].m_y, normals[index].m_z);
				object->textureCoord (uv0[index].m_u, uv0[index].m_v);
				vertexCount ++;
			}
			indexList[i] = remapIndex[index];
			
		}

		for (int i = 0; i < indexCount; i += 3) {
			object->triangle (indexList[i + 0], indexList[i + 1], indexList[i + 2]);
		}
		object->end();
	}
	EndMaterialHandle (materialsHandle); 

	return object;
}
Exemplo n.º 3
0
Void PointMesh::GetPoint( UInt iPoint, UInt & outA ) const
{
    Assert( iPoint < GetPointCount() );

    outA = iPoint;

    if ( m_pIB == NULL )
        return;

    const Byte * pIndexA = m_pIB->GetData( m_iIndexOffset + outA );
    if ( m_pIB->UseShorts() )
        outA = *( (const Word*)pIndexA );
    else
        outA = *( (const DWord*)pIndexA );
}
void ScanData::dummy_data(EventReceiver *erx)
{
    //freq_start = 26205000.0;
    //freq_end = 28205000.0;
    double freq_inc = (freq_end-freq_start)/GetPointCount();

    for (unsigned int i=0;i<points.size();i++)
    {
        points[i].freq = freq_start + i*freq_inc;
        points[i].swr = 5.1 + sin(double(i)/(points.size()-1)*2*3.14159)*4.0;
        points[i].Z = 100 + cos(double(i)/(points.size()-1)*2*3.14159)*50;
//printf("%d: %lf => %lf\n",i,points[i].freq,points[i].swr);
        erx->RaiseEvent(EventReceiver::progress_event, i*100/(points.size()-1));
    }
//fflush(stdout);
    UpdateStats();
}
Exemplo n.º 5
0
Point *ObjectManager::GetPointFromID(int ID)
{
    int count = GetPointCount();
    if( count ) 
    {
        for(int i = 0; i < count; i++)
        {
            Point* pPoint = (Point*)m_vecPoints[i];
            if(pPoint->GetID() == ID)
            {

                return pPoint;
            }
        }
    }
    return NULL;
}
Exemplo n.º 6
0
double *CPlotData::GetTimePoints()
{
  size_t nPoints = GetPointCount();
  if((nPoints > 0) && (m_pdX == NULL))
  {
    double *p;
    unsigned int i;
    unsigned int nValue = m_nStart;
    size_t nSize = nPoints * sizeof(double);
    m_pdX = (double *)malloc(nSize);
    memset(m_pdX,0,nSize);
    p = m_pdX;
    for(i = 0; i < nPoints; i++)
    {
      (*p) = double(nValue);
      nValue += m_nInterval;
      p++;
    }
  }
  return m_pdX;
}
Exemplo n.º 7
0
void ConvexPolygon2D::ClipToLine(const Line2D &line) {
  if (GetPointCount() == 0) return;
  std::vector<D3DXVECTOR2> new_points;
  D3DXVECTOR2 p0 = points_[points_.size()-1];
  bool p0_inside = line.Distance(p0) < 0;
  std::vector<D3DXVECTOR2>::const_iterator it;
  for (it = points_.begin(); it != points_.end(); ++it) {
    const D3DXVECTOR2 &p1 = *it;
    bool p1_inside = line.Distance(p1) < 0;
    if (p0_inside && p1_inside) {
      new_points.push_back(p1);
    } else if (p0_inside && !p1_inside) {
      new_points.push_back(line.Intersection(Line2D(p0, p1)));
    } else if (!p0_inside && p1_inside) {
      new_points.push_back(line.Intersection(Line2D(p0, p1)));
      new_points.push_back(p1);
    } else {
      // do nothing
    }
    p0 = p1;
    p0_inside = p1_inside;
  }
  points_.swap(new_points);
}
Exemplo n.º 8
0
void Header::write()
{

    uint8_t n1 = 0;
    uint16_t n2 = 0;
    uint32_t n4 = 0;


    // Figure out how many points we already have.  
    // Figure out if we're in append mode.  If we are, we can't rewrite 
    // any of the VLRs including the Schema and SpatialReference ones.
    bool bAppendMode = false;

    // This test should only be true if we were opened in both 
    // std::ios::in *and* std::ios::out

    // Seek to the beginning
    GetStream().seekp(0, ios::beg);
    ios::pos_type begin = GetStream().tellp();

    // Seek to the end
    GetStream().seekp(0, ios::end);
    ios::pos_type end = GetStream().tellp();
    if ((begin != end) && (end != static_cast<ios::pos_type>(0))) {
        bAppendMode = true;
    }

    // If we are in append mode, we are not touching *any* VLRs. 
    if (bAppendMode) 
    {
        // We're opened in append mode
        
        ios::off_type points = end - static_cast<ios::off_type>(m_header.GetDataOffset());
        ios::off_type count = points / static_cast<ios::off_type>(m_header.GetDataRecordLength());
        
        if (points < 0) {
            std::ostringstream oss;
            oss << "The header's data offset," << m_header.GetDataOffset() 
                <<", is much larger than the size of the file, " << end
                <<", and something is amiss.  Did you use the right header"
                <<" offset value?";
            throw std::runtime_error(oss.str());
        }

        uint32_t& cnt =  GetPointCount();
        cnt = static_cast<uint32_t>(count);
        SetPointCount(cnt);

        // Position to the beginning of the file to start writing the header
        GetStream().seekp(0, ios::beg);

    } 
    else 
    {
        // Rewrite the georeference VLR entries if they exist
        m_header.SetGeoreference();

        // If we have a custom schema, add the VLR and write it into the 
        // file.  
        if (m_header.GetSchema().IsCustom()) {
            
            // Wipe any schema-related VLRs we might have, as this is now out of date.
            m_header.DeleteVLRs("liblas", 7);
        
            VariableRecord v = m_header.GetSchema().GetVLR();
            std::cout <<  m_header.GetSchema()<< std::endl;
            m_header.AddVLR(v);
        }
    
        int32_t difference = m_header.GetDataOffset() - GetRequiredHeaderSize();

        if (difference <= 0) 
        {
            int32_t d = abs(difference);
            if (m_header.GetVersionMinor()  ==  0) 
            {
                // Add the two extra bytes for the 1.0 pad
                d = d + 2;
            }
            m_header.SetDataOffset(m_header.GetDataOffset() + d );
        }

    }

    
    // 1. File Signature
    std::string const filesig(m_header.GetFileSignature());
    assert(filesig.size() == 4);
    detail::write_n(GetStream(), filesig, 4);
    
    
    // 2. File SourceId / Reserved
    if (m_header.GetVersionMinor()  ==  0) {
        n4 = m_header.GetReserved();
        detail::write_n(GetStream(), n4, sizeof(n4));         
    } else if (m_header.GetVersionMinor()  >  0) {
        n2 = m_header.GetFileSourceId();
        detail::write_n(GetStream(), n2, sizeof(n2));                
        n2 = m_header.GetReserved();
        detail::write_n(GetStream(), n2, sizeof(n2));        
    } 

    // 3-6. GUID data
    uint32_t d1 = 0;
    uint16_t d2 = 0;
    uint16_t d3 = 0;
    uint8_t d4[8] = { 0 };
    liblas::guid g = m_header.GetProjectId();
    g.output_data(d1, d2, d3, d4);
    detail::write_n(GetStream(), d1, sizeof(d1));
    detail::write_n(GetStream(), d2, sizeof(d2));
    detail::write_n(GetStream(), d3, sizeof(d3));
    detail::write_n(GetStream(), d4, sizeof(d4));
    
    // 7. Version major
    n1 = m_header.GetVersionMajor();
    assert(1 == n1);
    detail::write_n(GetStream(), n1, sizeof(n1));
    
    // 8. Version minor
    n1 = m_header.GetVersionMinor();
    detail::write_n(GetStream(), n1, sizeof(n1));

    // 9. System ID
    std::string sysid(m_header.GetSystemId(true));
    assert(sysid.size() == 32);
    detail::write_n(GetStream(), sysid, 32);
    
    // 10. Generating Software ID
    std::string softid(m_header.GetSoftwareId(true));
    assert(softid.size() == 32);
    detail::write_n(GetStream(), softid, 32);

    // 11. Flight Date Julian
    n2 = m_header.GetCreationDOY();
    detail::write_n(GetStream(), n2, sizeof(n2));

    // 12. Year
    n2 = m_header.GetCreationYear();
    detail::write_n(GetStream(), n2, sizeof(n2));

    // 13. Header Size
    n2 = m_header.GetHeaderSize();
    assert(227 <= n2);
    detail::write_n(GetStream(), n2, sizeof(n2));

    // 14. Offset to data
    n4 = m_header.GetDataOffset();        
    detail::write_n(GetStream(), n4, sizeof(n4));

    // 15. Number of variable length records
    n4 = m_header.GetRecordsCount();
    detail::write_n(GetStream(), n4, sizeof(n4));

    // 16. Point Data Format ID
    n1 = static_cast<uint8_t>(m_header.GetDataFormatId());
    detail::write_n(GetStream(), n1, sizeof(n1));

    // 17. Point Data Record Length
    n2 = m_header.GetDataRecordLength();
    detail::write_n(GetStream(), n2, sizeof(n2));

    // 18. Number of point records
    // This value is updated if necessary, see UpdateHeader function.
    n4 = m_header.GetPointRecordsCount();
    detail::write_n(GetStream(), n4, sizeof(n4));

    // 19. Number of points by return
    std::vector<uint32_t>::size_type const srbyr = 5;
    std::vector<uint32_t> const& vpbr = m_header.GetPointRecordsByReturnCount();
    // TODO: fix this for 1.3, which has srbyr = 7;  See detail/reader/header.cpp for more details
    // assert(vpbr.size() <= srbyr);
    uint32_t pbr[srbyr] = { 0 };
    std::copy(vpbr.begin(), vpbr.begin() + srbyr, pbr); // FIXME: currently, copies only 5 records, to be improved
    detail::write_n(GetStream(), pbr, sizeof(pbr));

    // 20-22. Scale factors
    detail::write_n(GetStream(), m_header.GetScaleX(), sizeof(double));
    detail::write_n(GetStream(), m_header.GetScaleY(), sizeof(double));
    detail::write_n(GetStream(), m_header.GetScaleZ(), sizeof(double));

    // 23-25. Offsets
    detail::write_n(GetStream(), m_header.GetOffsetX(), sizeof(double));
    detail::write_n(GetStream(), m_header.GetOffsetY(), sizeof(double));
    detail::write_n(GetStream(), m_header.GetOffsetZ(), sizeof(double));

    // 26-27. Max/Min X
    detail::write_n(GetStream(), m_header.GetMaxX(), sizeof(double));
    detail::write_n(GetStream(), m_header.GetMinX(), sizeof(double));

    // 28-29. Max/Min Y
    detail::write_n(GetStream(), m_header.GetMaxY(), sizeof(double));
    detail::write_n(GetStream(), m_header.GetMinY(), sizeof(double));

    // 30-31. Max/Min Z
    detail::write_n(GetStream(), m_header.GetMaxZ(), sizeof(double));
    detail::write_n(GetStream(), m_header.GetMinZ(), sizeof(double));

    // If WriteVLR returns a value, it is because the header's 
    // offset is not large enough to contain the VLRs.  The value 
    // it returns is the number of bytes we must increase the header
    // by in order for it to contain the VLRs.  We do not touch VLRs if we 
    // are in append mode.

    if (!bAppendMode) 
    {
        WriteVLRs();

        // Write the 1.0 pad signature if we need to.
        WriteLAS10PadSignature(); 

    }           
    // If we already have points, we're going to put it at the end of the file.  
    // If we don't have any points,  we're going to leave it where it is.
    if (GetPointCount() != 0)
        GetStream().seekp(0, std::ios::end);
    
}