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 4126200
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:58:10+00:00 2026-05-20T23:58:10+00:00

I’m pretty new to C++ so I’m not sure I’m going about this problem

  • 0

I’m pretty new to C++ so I’m not sure I’m going about this problem in the right way. I’m dealing with a 3D array of voxel data and I would like to create a parallel data structure to store isosurface normal vectors. Memory efficiency is an issue so I thought to use a 2D array of maps, which are indexed by an integer and contain a 3D vector.

The idea being the 2D array indexes every x and y coordinate and the maps index only the z coordinates containing a value (typically between 0 and 3 values dispersed along each row of the z axis).

Question 1: how do I create a 2D array of maps like std::map<int, Vector3f> surfaceNormals; ?

Question 2: My idea is declare the 2D array global then to populate it with a function which deals with it by pointer and creates a map for each array cell, is the code below on the right track? the ?????’s indicate where i’m not sure what to put given my uncertainty about Question 1.

In particular am I managing pointers/references/values correctly such as to actually end up storing all the data I need?

????? isoSurfaces1 [256][100];

????? *extractIS(float Threshold, ????? *pointy){

   ????? *surfacePointer = pointy;

   for loop over x and y {

      std::map<int, Vector3f> surfaceNormals;

      for loop over z {

         [ ... find surface voxels and their normal vectors ... ]

         Vector3f newNormalVector(x,y,z);

         surfaceNormals[zi] = newNormalVector;
      }           

      surfacePointer[x][y] = surfaceNormals;
   }

   return surfacePointer;
}

extractIS(0.45, isoSurfaces1);
  • 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-20T23:58:11+00:00Added an answer on May 20, 2026 at 11:58 pm

    If i understood you correctly, you want to use the coordinate as a std::map key?

    You could just create 1 dimensional std::map, and convert the XYZ coordinates into 1 dimensional coordinate system:

    int pos1d = z*max_x*max_y+y*max_x+x;
    

    and then just put that to the map key.

    Edit: or you could just use a struct with x,y,z as integers as Space_C0wb0y showed, but that will of course take 3x more memory per std::map key, also note that the example i showed will have the maximum cube size: 1625x1625x1625 (if unsigned int), so if you need longer coordinates then use a struct, but note that with structs you have to write comparisor function for the std::map key datatype.

    Edit3:
    I think this is what you are looking for, as i noticed you used max 256 coordinate value, here is what i came up with:

    // NOTE: max 256x256x256 cube coordinates with this struct. change unsigned char to short or int etc if you need larger values.
    // also note that if you change to something else than unsigned char, you cant use nor compare the union: v1.Pos > v2.Pos anymore. 
    // (unless you use unsigned short for each coordinate, and unsigned __int64 for the union Pos value)
    
    union PosXYZ {
        struct {
            unsigned char x, y, z, padding; // use full 32bits for better performance
        };
        unsigned __int32 Pos; // assure its 32bit even on 64bit machines
    
        PosXYZ(unsigned char x, unsigned char y, unsigned char z) : x(x), y(y), z(z), padding(0) {} // initializer list, also set padding to zero so Pos can be compared correctly.
    };   
    
    
    inline bool operator>(const PosXYZ &v1, const PosXYZ &v2){
        return v1.Pos > v2.Pos;
    }
    
    
    typedef map<PosXYZ, Vector3f, greater<PosXYZ> > MyMap;
    
    
    void extractIS(float Threshold, MyMap &surfacePointer){
        for loop over x and y {
            for loop over z {
                // [ ... find surface voxels and their normal vectors ... ]
                Vector3f newNormalVector(x,y,z);
    
                surfacePointer[PosXYZ(x,y,z)] = newNormalVector;
            }           
        }
    }
    
    
    MyMap isoSurfaces1;
    
    extractIS(0.45, isoSurfaces1);
    

    Another way to do this std::map key struct is to just use plain integer value, which you would generate via your own function similar to: ((x << 16) | (y << 8) | z), this will simplify things a little since you dont need the comparisor function for std::map anymore.

    #define PosXYZ(x,y,z) (((x) << 16) | ((y) << 8) | (z)) // generates the std::map key for 256x256x256 max cube coords.
    
    typedef map<unsigned __int32, Vector3f, greater<unsigned __int32> > MyMap;
    
    
    void extractIS(float Threshold, MyMap &surfacePointer){
        for loop over x and y {
            for loop over z {
                // [ ... find surface voxels and their normal vectors ... ]
                Vector3f newNormalVector(x,y,z);
    
                surfacePointer[PosXYZ(x,y,z)] = newNormalVector;
            }           
        }
    }
    
    
    MyMap isoSurfaces1;
    
    extractIS(0.45, isoSurfaces1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I want use html5's new tag to play a wav file (currently only supported

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.