Exemplo n.º 1
0
// ElementRangeSize
float
LayoutInfo::ElementRangeSize(int32 position, int32 length)
{
	if (length == 1)
		return ElementSize(position);

	int lastIndex = position + length - 1;
	return ElementLocation(lastIndex) + ElementSize(lastIndex)
		- ElementLocation(position);
}
Exemplo n.º 2
0
ERRORCODE Array::set_array_size(SHORT new_count)
{
	int nElementSize = ElementSize();

/* See if there's anything to do. */

	if (new_count == element_count)
	{
		return ERRORCODE_None;
	}

/*
// See if it's time to free the data.
*/

	if (new_count == 0)
	{
	/* No more data. Free the data area. */
		free_data();
	}
	else
	{
	/*
	// Try to reallocate the array data.
	// If "data" is NULL to begin with, this should allocate memory.
	*/
		/* Only allocate if getting larger. */
		if (new_count > m_nBlockCount || data == NULL)
		{
			// Allocate new data.
			LPVOID new_data = NULL;
			TRY
				new_data = (LPVOID)(new BYTE [nElementSize*new_count]);
			END_TRY

			if (new_data == NULL)
			{
				return ERRORCODE_Memory;
			}

			// If we have old data, copy it over now.
			if (data != NULL)
			{
				// Copy over the data from the old block.
				int nCount = __min(new_count, m_nBlockCount);
				memcpy(new_data, data, nCount*nElementSize);
				free_data();
			}
			// Plug in the new data.
			data = new_data;
			m_nBlockCount = new_count;
		}
	}
Exemplo n.º 3
0
//==============================================================================
int * Epetra_BlockMap::PointToElementList() const {

  // If PointToElementList not built, do so
  if ((BlockMapData_->PointToElementList_.Length() == 0) && (BlockMapData_->NumMyPoints_ > 0)) {
    BlockMapData_->PointToElementList_.Size(BlockMapData_->NumMyPoints_);
    int numMyElements = BlockMapData_->NumMyElements_;
    int * ptr = BlockMapData_->PointToElementList_.Values();
    for (int i = 0; i < numMyElements; i++) {
      int Size = ElementSize(i);
      for (int j = 0; j < Size; j++) 
  *ptr++ = i;
    }
  }
  return(BlockMapData_->PointToElementList_.Values());
}
Exemplo n.º 4
0
//==============================================================================
int Epetra_BlockMap::PointToElementList(int * pointToElementList) const {
  // Build an array such that the local element ID is stored for each point

  int i;
  if (BlockMapData_->PointToElementList_.Length() == 0) {
    int numMyElements = BlockMapData_->NumMyElements_;
    int * ptr = pointToElementList;
    for (i = 0; i < numMyElements; i++) {
      int Size = ElementSize(i);
      for (int j = 0; j < Size; j++) 
  *ptr++ = i;
    }
  }
  else {
    int numMyPoints = BlockMapData_->NumMyPoints_;
    for (i = 0; i < numMyPoints; i++)
      pointToElementList[i] = BlockMapData_->PointToElementList_[i];
  }
  return(0);
}
void StateRenderTest::InitGrid(beRenderInterface* renderInterface)
{
	const int gridRadius = 100;
	const float gridSize = 1.f;
	const float xyOffset = gridSize / 2.f; // Don't draw on same spot as renderAxes
	const float gridOffset = ((float)gridRadius / 2.f);

	const int quadCount = gridRadius * gridRadius;
	const int vertexCount = quadCount * 8;
	const int triCount = quadCount * 2;
	const int triIndexCount = triCount * 3;

	const float noiseScale = 5.f;
	const float noiseHeight = 8.f;
	beRandom rng;
	rng.InitFromSystemTime();
	bePerlinNoise2D noise;
	noise.Initialise(rng.Next());

	beVector<beShaderColour::VertexType> vertices(vertexCount, vertexCount, 0);
	beVector<u32> lineIndices(vertexCount, vertexCount, 0);
	beVector<u32> triIndices(triIndexCount, triIndexCount, 0);

	for (int i : RangeIter(lineIndices.Count()))
	{
		lineIndices[i] = i;
	}

	for (int i : RangeIter(quadCount))
	{
		const int triListIndex = i * 6;
		const int lineListIndex = i * 8;
		triIndices[triListIndex+0] = lineListIndex+0;
		triIndices[triListIndex+1] = lineListIndex+2;
		triIndices[triListIndex+2] = lineListIndex+4;

		triIndices[triListIndex+3] = lineListIndex+4;
		triIndices[triListIndex+4] = lineListIndex+6;
		triIndices[triListIndex+5] = lineListIndex+0;
	}

	int vertexIndex = 0;
	for (float x = -gridOffset; x < gridOffset; x += gridSize)
	{
		const float xPos0 = x + xyOffset;
		const float xPos1 = xPos0+gridSize;
		for (float y = -gridOffset; y < gridOffset; y += gridSize)
		{
			const float yPos0 = y + xyOffset;
			const float yPos1 = yPos0+gridSize;

			const float zPos0 = noiseHeight * noise.GetOctave(xPos0/noiseScale, yPos0/noiseScale, 4);
			const float zPos1 = noiseHeight * noise.GetOctave(xPos0/noiseScale, yPos1/noiseScale, 4);
			const float zPos2 = noiseHeight * noise.GetOctave(xPos1/noiseScale, yPos1/noiseScale, 4);
			const float zPos3 = noiseHeight * noise.GetOctave(xPos1/noiseScale, yPos0/noiseScale, 4);

			const Vec4 pos0(xPos0, yPos0, zPos0, 1.f);
			const Vec4 pos1(xPos0, yPos1, zPos1, 1.f);
			const Vec4 pos2(xPos1, yPos1, zPos2, 1.f);
			const Vec4 pos3(xPos1, yPos0, zPos3, 1.f);

			//LOG("[{},{}] 0- {}", x, y, pos0);
			//LOG("[{},{}] 1- {}", x, y, pos1);
			//LOG("[{},{}] 2- {}", x, y, pos2);
			//LOG("[{},{}] 3- {}", x, y, pos3);

			vertices[vertexIndex+0].position = pos0;
			vertices[vertexIndex+1].position = pos1;
			vertices[vertexIndex+2].position = pos1;
			vertices[vertexIndex+3].position = pos2;  
			vertices[vertexIndex+4].position = pos2;
			vertices[vertexIndex+5].position = pos3;
			vertices[vertexIndex+6].position = pos3;
			vertices[vertexIndex+7].position = pos0;
			vertices[vertexIndex+0].colour = Vec4(zPos0 / noiseHeight, zPos0 / noiseHeight, 1.f, 1.f);
			vertices[vertexIndex+1].colour = Vec4(zPos1 / noiseHeight, zPos1 / noiseHeight, 1.f, 1.f);
			vertices[vertexIndex+2].colour = Vec4(zPos1 / noiseHeight, zPos1 / noiseHeight, 1.f, 1.f);
			vertices[vertexIndex+3].colour = Vec4(zPos2 / noiseHeight, zPos2 / noiseHeight, 1.f, 1.f);
			vertices[vertexIndex+4].colour = Vec4(zPos2 / noiseHeight, zPos2 / noiseHeight, 1.f, 1.f);
			vertices[vertexIndex+5].colour = Vec4(zPos3 / noiseHeight, zPos3 / noiseHeight, 1.f, 1.f);
			vertices[vertexIndex+6].colour = Vec4(zPos3 / noiseHeight, zPos3 / noiseHeight, 1.f, 1.f);
			vertices[vertexIndex+7].colour = Vec4(zPos0 / noiseHeight, zPos0 / noiseHeight, 1.f, 1.f);
			vertexIndex += 8; 
		}
	}

	beRenderBuffer vertexBuffer, indexBuffer, linesIndexB;

	vertexBuffer.Allocate(renderInterface, ElementSize(vertices), vertexCount, D3D11_USAGE_DEFAULT, D3D11_BIND_VERTEX_BUFFER, 0, 0, 0, vertices.begin());

	beModel::Material materials[1];
	materials[0].m_shader = beRendering::ShaderType::Colour;

	beModel::Mesh meshes[2];
	meshes[0].m_name = beString("GroundFilled");
	meshes[0].m_indexBuffer.Allocate(renderInterface, decltype(triIndices)::element_size, triIndices.Count(), D3D11_USAGE_DEFAULT, D3D11_BIND_INDEX_BUFFER, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST, 0, 0, triIndices.begin());
	meshes[0].m_materialIndex = 0;
	meshes[0].m_enabled = false;

	meshes[1].m_name = beString("GroundLines");
	meshes[1].m_indexBuffer.Allocate(renderInterface, decltype(lineIndices)::element_size, vertexCount, D3D11_USAGE_DEFAULT, D3D11_BIND_INDEX_BUFFER, D3D11_PRIMITIVE_TOPOLOGY_LINELIST, 0, 0, lineIndices.begin());
	meshes[1].m_materialIndex = 0;

	const bool success = m_gridModel.InitFromBuffers(&vertexBuffer, meshes, materials);
	if (!success) { BE_ASSERT(false); return; }
}
Exemplo n.º 6
0
EbmlElement *
kax_file_c::read_one_element() {
  if (m_segment_end && (m_in.getFilePointer() >= m_segment_end))
    return nullptr;

  auto upper_lvl_el = 0;
  auto l1           = m_es->FindNextElement(EBML_CLASS_CONTEXT(KaxSegment), upper_lvl_el, 0xFFFFFFFFL, true);

  if (!l1)
    return nullptr;

  auto callbacks = find_ebml_callbacks(EBML_INFO(KaxSegment), EbmlId(*l1));
  if (!callbacks)
    callbacks = &EBML_CLASS_CALLBACK(KaxSegment);

  auto l2 = static_cast<EbmlElement *>(nullptr);
  try {
    l1->Read(*m_es.get(), EBML_INFO_CONTEXT(*callbacks), upper_lvl_el, l2, true);

  } catch (std::runtime_error &e) {
    mxdebug_if(m_debug_resync, boost::format("exception reading element data: %1%\n") % e.what());
    m_in.setFilePointer(l1->GetElementPosition() + 1);
    delete l1;
    return nullptr;
  }

  auto element_size = get_element_size(l1);
  if (m_debug_resync)
    mxinfo(boost::format("kax_file::read_one_element(): read element at %1% calculated size %2% stored size %3%\n")
           % l1->GetElementPosition() % element_size % (l1->IsFiniteSize() ? (boost::format("%1%") % l1->ElementSize()).str() : std::string("unknown")));
  m_in.setFilePointer(l1->GetElementPosition() + element_size, seek_beginning);

  return l1;
}
Exemplo n.º 7
0
//==============================================================================
void Epetra_BlockMap::Print(ostream & os) const
{
  int * FirstPointInElementList1 = 0;
  int * ElementSizeList1 = 0;
  if (!ConstantElementSize()) {
    FirstPointInElementList1 = FirstPointInElementList();
    ElementSizeList1 = ElementSizeList();
  }
  int MyPID = Comm().MyPID();
  int NumProc = Comm().NumProc();
  
  for (int iproc = 0; iproc < NumProc; iproc++) {
    if (MyPID == iproc) {
      if (MyPID == 0) {
  os <<  "\nNumber of Global Elements  = "; os << NumGlobalElements64(); os << endl;
  os <<    "Number of Global Points    = "; os << NumGlobalPoints64(); os << endl;
  os <<    "Maximum of all GIDs        = "; os << MaxAllGID64(); os << endl;
  os <<    "Minimum of all GIDs        = "; os << MinAllGID64(); os << endl;
  os <<    "Index Base                 = "; os << IndexBase(); os << endl;
  if (ConstantElementSize())
    os <<  "Constant Element Size      = "; os << ElementSize(); os << endl;
      }
      os << endl;
      
      os <<    "Number of Local Elements   = "; os << NumMyElements(); os << endl;
      os <<    "Number of Local Points     = "; os << NumMyPoints(); os << endl;
      os <<    "Maximum of my GIDs         = "; os << MaxMyGID64(); os << endl;
      os <<    "Minimum of my GIDs         = "; os << MinMyGID64(); os << endl;
      os << endl;
      
      os.width(14);
      os <<  "     MyPID"; os << "    ";
      os.width(14);
      os <<  "       Local Index "; os << " ";
      os.width(14);
      os <<  "      Global Index "; os << " ";
      if (!ConstantElementSize()) {
  os.width(14);
  os <<" FirstPointInElement "; os << " ";
  os.width(14);
  os <<"   ElementSize "; os << " ";
      }
      os << endl;
      
      for (int i = 0; i < NumMyElements(); i++) {
  os.width(14);
  os <<  MyPID; os << "    ";
  os.width(14);
  os <<  i; os << "    ";
  os.width(14);

  if(BlockMapData_->GlobalIndicesLongLong_)
  {
#ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
    long long * MyGlobalElements1 = MyGlobalElements64();
    os <<  MyGlobalElements1[i]; os << "    ";
#else
    throw ReportError("Epetra_BlockMap::Print: ERROR, GlobalIndicesLongLong but no API for it.",-1);
#endif
  }
  else if(BlockMapData_->GlobalIndicesInt_)
  {
#ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
    int * MyGlobalElements1 = MyGlobalElements();
    os <<  MyGlobalElements1[i]; os << "    ";
#else
    throw ReportError("Epetra_BlockMap::Print: ERROR, no GlobalIndicesLongLong but no API for it.",-1);
#endif
  }

  if (!ConstantElementSize()) {    
    os.width(14);
    os << FirstPointInElementList1[i]; os << "    ";
    os.width(14);
    os << ElementSizeList1[i]; os << "    ";
  }
  os << endl;
      }
      
      os << flush;
      
    }
    // Do a few global ops to give I/O a chance to complete
    Comm().Barrier();
    Comm().Barrier();
    Comm().Barrier();
  }
  return;
}