Пример #1
0
void Mesh::texcoord(AlloArray *lat) {
	if(
		(lat->header.components == 2 || lat->header.components == 3) &&
		lat->header.type == AlloFloat32Ty && 
		lat->header.dimcount <= 2
	) {
		int components = lat->header.components;
		int w = lat->header.dim[0];
		int h = (lat->header.dimcount < 2) ? 1 : lat->header.dim[1];
		int ncells = w*h;
		
		if(components == 2) {
			mTexCoord2s.size(ncells);
		}
		else {
			mTexCoord3s.size(ncells);
		}
		
		char *v = (components == 2 ? (char *)mTexCoord2s.elems() : (char *)mTexCoord3s.elems());
		int rowstride = lat->header.stride[1];
		int rowsize = w * components * allo_type_size(AlloFloat32Ty);
		for(int j=0; j < h; j++) {
			char *vdata = (char *)(v + j*rowsize);
			char *data = lat->data.ptr + j*rowstride;
			memcpy(vdata, data, rowsize);
		}
	}
	else {
		fprintf(stderr, "Mesh::texcoord: array must be 2 or 3 component Float32");
	}
}
void fromCV(Array& arr, const cv::Mat& mat, int copyPolicy, int rowByteAlign) {

    AlloArrayHeader hdr;
    fromCV(hdr, mat, rowByteAlign);
    arr.format(hdr);	// allocates memory (when necessary)

    //printf("%d x %d; %d %d\n", mat.size[1], mat.size[0], mat.step[1], mat.step[0]);
    //arr.print();

    // Only copy as many bytes as is necessary (ignoring alignment, padding, etc.)
    int widthBytes = arr.width() * arr.components() * allo_type_size(arr.type());

    // Note: copies must be done row-by-row due to cv::Mat row padding
    switch(copyPolicy) {
    case  1:	// Copy rows in same order
        for(unsigned j=0; j<arr.height(); ++j) {
            memcpy(
                arr.cell<char>(0,j),
                mat.ptr(j,0), // cv convention is row,col
                widthBytes
            );
        }
        break;

    case -1:	// Copy with rows flipped
        for(unsigned j=0; j<arr.height(); ++j) {
            memcpy(
                arr.cell<char>(0,arr.height()-j-1),
                mat.ptr(j,0), // cv convention is row,col
                widthBytes
            );
        }
        break;

        //case 2:	// Copy data byte for byte
        //memcpy(arr.data.ptr, (const char *)mat.ptr(), arr.size());

        //case 0:		// Reference data?
        // Probably not a good idea since mat is const...
        //arr.data.ptr = (char *)mat.ptr();
        break;

    default:
        ;
    }
}
void allo_array_setstride(AlloArrayHeader * h, unsigned alignSize){
	unsigned typeSize = allo_type_size(h->type);
	unsigned numDims = h->dimcount;
	h->stride[0] = h->components * typeSize;

	if(numDims>1){
		h->stride[1] = h->stride[0] * h->dim[0]; /* compute ideal row stride amount */

		/* Pad rows to make multiple of alignment */
		if(alignSize > 1){
			unsigned remain = h->stride[1] % alignSize;		/* compute pad bytes */
			if(remain){ h->stride[1] += alignSize - remain;}/* add pad bytes (if any) */
		}

		unsigned i=2;
		for(; i<numDims; ++i){ h->stride[i] = h->stride[i-1] * h->dim[i-1]; }
	}
}
Пример #4
0
void Mesh::index(AlloArray *lat) {
	if(
		lat->header.components == 1 &&
		lat->header.type == AlloUInt32Ty && 
		lat->header.dimcount <= 2
	) {
		int w = lat->header.dim[0];
		int h = (lat->header.dimcount < 2) ? 1 : lat->header.dim[1];
		int ncells = w*h;
		mIndices.size(ncells);
		
		Index *v = mIndices.elems();
		int rowstride = lat->header.stride[1];
		int rowsize = w * allo_type_size(AlloUInt32Ty);
		for(int j=0; j < h; j++) {
			char *vdata = (char *)(v + j*w);
			char *data = lat->data.ptr + j*rowstride;
			memcpy(vdata, data, rowsize);
		}
	}
	else {
		fprintf(stderr, "Mesh::index: array must be 1 component UInt32");
	}
}
Пример #5
0
void Mesh::color(AlloArray *lat) {
	if(
		lat->header.components == 4 &&
		lat->header.type == AlloFloat32Ty && 
		lat->header.dimcount <= 2
	) {
		int w = lat->header.dim[0];
		int h = (lat->header.dimcount < 2) ? 1 : lat->header.dim[1];
		int ncells = w*h;
		mColors.size(ncells);
		
		Color *v = mColors.elems();
		int rowstride = lat->header.stride[1];
		int rowsize = w * 4 * allo_type_size(AlloFloat32Ty);
		for(int j=0; j < h; j++) {
			char *vdata = (char *)(v + j*w);
			char *data = lat->data.ptr + j*rowstride;
			memcpy(vdata, data, rowsize);
		}
	}
	else {
		fprintf(stderr, "Mesh::color: array must be 4 component Float32");
	}
}
Пример #6
0
	int getPlanes() const {
		AlloTy type = getDataType();
		BITMAPINFOHEADER * hdr = FreeImage_GetInfoHeader(mImage);
		return (hdr->biBitCount)/(8*allo_type_size(type));
	}