本文整理汇总了C++中Array::GetDataPtr方法的典型用法代码示例。如果您正苦于以下问题:C++ Array::GetDataPtr方法的具体用法?C++ Array::GetDataPtr怎么用?C++ Array::GetDataPtr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Array
的用法示例。
在下文中一共展示了Array::GetDataPtr方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: exit
void SprsArray<Dtype>::Create(const Array<Dtype>& array) {
// verify the array
if (array.GetDimCnt() != 2) {
std::cout << "[ERROR] the input array must be 2-dimensional" << std::endl;
exit(-1);
} // ENDIF: array
// obtain basic variables
rowCnt_ = array.GetDimLen(0);
colCnt_ = array.GetDimLen(1);
nnzCnt_ = 0;
std::size_t eleCnt = array.GetEleCnt();
const Dtype* pData = array.GetDataPtr();
for (std::size_t eleIdx = 0; eleIdx < eleCnt; ++eleIdx) {
if (ABS(pData[eleIdx]) > kEpsilon) {
nnzCnt_++;
} // ENDIF: ABS
} // ENDFOR: eleIdx
// release space occupied by previous pointers (if any)
Delete();
// allocate space for pointers
val_ = new Dtype[nnzCnt_];
idx_ = new MKL_INT[nnzCnt_];
ptrb_ = new MKL_INT[rowCnt_];
ptre_ = new MKL_INT[rowCnt_];
// convert the dense array to CSR format, zero-based indexing)
std::size_t nnzIdx = 0;
for (std::size_t rowIdx = 0; rowIdx < rowCnt_; ++rowIdx) {
// initialize variables for the current row
const Dtype* pData = array.GetDataPtr() + rowIdx * colCnt_;
bool isFirst = true;
// scan through the current row
for (std::size_t colIdx = 0; colIdx < colCnt_; ++colIdx) {
if (ABS(pData[colIdx]) > kEpsilon) {
val_[nnzIdx] = pData[colIdx];
idx_[nnzIdx] = colIdx;
if (isFirst) {
isFirst = false;
ptrb_[rowIdx] = nnzIdx;
} // ENDIF: isFirst
ptre_[rowIdx] = ++nnzIdx;
} // ENDIF: ABS
} // ENDFOR: colIdx
} // ENDFOR: rowIdx
}
示例2: Create
void GlGeometry::Create( const VertexAttribs & attribs, const Array< TriangleIndex > & indices )
{
vertexCount = attribs.position.GetSizeI();
indexCount = indices.GetSizeI();
glGenBuffers( 1, &vertexBuffer );
glGenBuffers( 1, &indexBuffer );
glGenVertexArraysOES_( 1, &vertexArrayObject );
glBindVertexArrayOES_( vertexArrayObject );
glBindBuffer( GL_ARRAY_BUFFER, vertexBuffer );
Array< uint8_t > packed;
PackVertexAttribute( packed, attribs.position, VERTEX_ATTRIBUTE_LOCATION_POSITION, GL_FLOAT, 3 );
PackVertexAttribute( packed, attribs.normal, VERTEX_ATTRIBUTE_LOCATION_NORMAL, GL_FLOAT, 3 );
PackVertexAttribute( packed, attribs.tangent, VERTEX_ATTRIBUTE_LOCATION_TANGENT, GL_FLOAT, 3 );
PackVertexAttribute( packed, attribs.binormal, VERTEX_ATTRIBUTE_LOCATION_BINORMAL, GL_FLOAT, 3 );
PackVertexAttribute( packed, attribs.color, VERTEX_ATTRIBUTE_LOCATION_COLOR, GL_FLOAT, 4 );
PackVertexAttribute( packed, attribs.uv0, VERTEX_ATTRIBUTE_LOCATION_UV0, GL_FLOAT, 2 );
PackVertexAttribute( packed, attribs.uv1, VERTEX_ATTRIBUTE_LOCATION_UV1, GL_FLOAT, 2 );
PackVertexAttribute( packed, attribs.jointIndices, VERTEX_ATTRIBUTE_LOCATION_JOINT_INDICES, GL_INT, 4 );
PackVertexAttribute( packed, attribs.jointWeights, VERTEX_ATTRIBUTE_LOCATION_JOINT_WEIGHTS, GL_FLOAT, 4 );
glBufferData( GL_ARRAY_BUFFER, packed.GetSize() * sizeof( packed[0] ), packed.GetDataPtr(), GL_STATIC_DRAW );
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, indexBuffer );
glBufferData( GL_ELEMENT_ARRAY_BUFFER, indices.GetSizeI() * sizeof( indices[0] ), indices.GetDataPtr(), GL_STATIC_DRAW );
glBindVertexArrayOES_( 0 );
glDisableVertexAttribArray( VERTEX_ATTRIBUTE_LOCATION_POSITION );
glDisableVertexAttribArray( VERTEX_ATTRIBUTE_LOCATION_NORMAL );
glDisableVertexAttribArray( VERTEX_ATTRIBUTE_LOCATION_TANGENT );
glDisableVertexAttribArray( VERTEX_ATTRIBUTE_LOCATION_BINORMAL );
glDisableVertexAttribArray( VERTEX_ATTRIBUTE_LOCATION_COLOR );
glDisableVertexAttribArray( VERTEX_ATTRIBUTE_LOCATION_UV0 );
glDisableVertexAttribArray( VERTEX_ATTRIBUTE_LOCATION_UV1 );
glDisableVertexAttribArray( VERTEX_ATTRIBUTE_LOCATION_JOINT_INDICES );
glDisableVertexAttribArray( VERTEX_ATTRIBUTE_LOCATION_JOINT_WEIGHTS );
}
示例3: PackVertexAttribute
void PackVertexAttribute( Array< uint8_t > & packed, const Array< _attrib_type_ > & attrib,
const int glLocation, const int glType, const int glComponents )
{
if ( attrib.GetSize() > 0 )
{
const size_t offset = packed.GetSize();
const size_t size = attrib.GetSize() * sizeof( attrib[0] );
packed.Resize( offset + size );
memcpy( &packed[offset], attrib.GetDataPtr(), size );
glEnableVertexAttribArray( glLocation );
glVertexAttribPointer( glLocation, glComponents, glType, false, sizeof( attrib[0] ), (void *)( offset ) );
}
else
{
glDisableVertexAttribArray( glLocation );
}
}
示例4: Update
void GlGeometry::Update( const VertexAttribs & attribs )
{
vertexCount = attribs.position.GetSizeI();
glBindVertexArrayOES_( vertexArrayObject );
glBindBuffer( GL_ARRAY_BUFFER, vertexBuffer );
Array< uint8_t > packed;
PackVertexAttribute( packed, attribs.position, VERTEX_ATTRIBUTE_LOCATION_POSITION, GL_FLOAT, 3 );
PackVertexAttribute( packed, attribs.normal, VERTEX_ATTRIBUTE_LOCATION_NORMAL, GL_FLOAT, 3 );
PackVertexAttribute( packed, attribs.tangent, VERTEX_ATTRIBUTE_LOCATION_TANGENT, GL_FLOAT, 3 );
PackVertexAttribute( packed, attribs.binormal, VERTEX_ATTRIBUTE_LOCATION_BINORMAL, GL_FLOAT, 3 );
PackVertexAttribute( packed, attribs.color, VERTEX_ATTRIBUTE_LOCATION_COLOR, GL_FLOAT, 4 );
PackVertexAttribute( packed, attribs.uv0, VERTEX_ATTRIBUTE_LOCATION_UV0, GL_FLOAT, 2 );
PackVertexAttribute( packed, attribs.uv1, VERTEX_ATTRIBUTE_LOCATION_UV1, GL_FLOAT, 2 );
PackVertexAttribute( packed, attribs.jointIndices, VERTEX_ATTRIBUTE_LOCATION_JOINT_INDICES, GL_INT, 4 );
PackVertexAttribute( packed, attribs.jointWeights, VERTEX_ATTRIBUTE_LOCATION_JOINT_WEIGHTS, GL_FLOAT, 4 );
glBufferData( GL_ARRAY_BUFFER, packed.GetSize() * sizeof( packed[0] ), packed.GetDataPtr(), GL_STATIC_DRAW );
}