Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6698993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:38:34+00:00 2026-05-26T06:38:34+00:00

Reading a raw 3d (256x256x256 cells) texture (8bit) using the following: f = fopen(file,

  • 0

Reading a raw 3d (256x256x256 cells) texture (8bit) using the following:

f = fopen(file, "rb");
if (f == NULL) return;
int size = width * height * depth;
data = new unsigned char[size*3];
fread(data, 3, size, f);
image = reinterpret_cast<rgb *>(data);
fclose(f);

where image rgba is

typedef unsigned char byte;

    typedef struct {
        byte r;
        byte g;
        byte b;
    } rgb;

I now want to “slice” the cube in some perpendicular direction and display the data with:

glTexImage2D()

What is a clever way to go about grabbing these slices? I have tried to get my head around how to grab the data using a loop, but I am not exactly sure how the data is orgaanized and I do not find this loop to be trivial.

Could I map the data into a more trivial format so I can use intuitive slice syntax?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:38:35+00:00Added an answer on May 26, 2026 at 6:38 am

    It’s just a 3D array. Pick two axes to scan in the standard 2D access pattern and vary the third to change slices:

    for( unsigned int slice = 0; i < numSlices; ++i )
    {
        for( unsigned int x = 0; x < xSize; ++x )
        {
            for( unsigned int y = 0; y < ySize; ++y )
            {
                // XY slice
                output[x][y] = array[x][y][slice];
    
                // XZ slice
                output[x][y] = array[x][slice][y];
    
                // YZ slice
                output[x][y] = array[slice][x][y];
            }
        }
    }
    

    You can get fancier with Boost.MultiArray.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In R am reading a file with comments as csv using read.data.raw = read.csv(inputfile,
I get the following error when reading in a text file of raw JSON
I am reading a raw audio file (CD track rip) in, doing byte swapping,
Using a very large raw binary data file, I will be creating a large
I'm reading sector-aligned chunks from a file using ReadFileEx (opened with CreateFile and the
I am having trouble reading a csv file, delimited by tabs, in python. I
I'm trying to write a bitmap (.bmp) parser/reader by reading raw bytes from the
I am looking for an efficient way of reading the raw text from any
I'm reading raw data from a mic and feeding into FFT. Two of the
I am reading from serial port using string messaga = _serialPort.ReadLine(); When i Console.WriteLine(messaga);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.