Toggle Contour Lines via Control Pipe?

Home Forums AR Sandbox Forum Toggle Contour Lines via Control Pipe?

This topic contains 5 replies, has 3 voices, and was last updated by  paguy 2 months, 1 week ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #118331

    anoia
    Participant

    Hello Forum,

    thanks to the instructions and this Forum our Sandbox here at a lab for schools in Berlin, Germany, looks really splendid.
    We managed to get everything going from HeightColorMaps to Lava shader, instead of USB Buttons we use a small control app on a tablet computer via VNC server on the box.
    There’s just one thing: Can one toggle the display of contour lines in the same way as water attenuation? I found posts about the spacing of lines, but none so far about switching them on and off in a running box software. Or, is there a compilation of parameters for the control pipe? I tried to set UseContourLines true/false, but to no avail so far.

    Thanks in advance
    Ralf Kreutel, DLR_School_Lab Berlin

    #118332

    Oliver Kreylos
    Keymaster

    There is currently no command for contour line control on the control pipe. All the commands it does understand are listed in the Sandbox class’s frame() method, in Sandbox.cpp around line 1178.

    #118346

    anoia
    Participant

    Thank you very much for the statement, I’ll have a look into it.

    #118387

    paguy
    Participant

    These work modifications work on 2.6 (but would probably work on an earlier version that supports control pipe commands)

    The changes add two control pipe variables

    • contourLineSpacing
    • useContourLines

    contourLineSpacing requires a decimal value that defines the contour spacing 0.5 to 2 seems to be a reasonable range.
    useContourLines requires a 1 or 0 depending if you want the lines on or off.

    Sandbox.h around line 142 add

    
    	float contourLineSpacing; // Contour line spacing for pipe
    	unsigned int useContourLine; //Contour lines on / off for pipe
    

    Sandbox.cpp line 1250 (has to be between the closing brace and the statement starting “else if(isToken(tokens[0]…”) add

    
    // ++Modification to enable contour line spacing through control pipe	
    else if(isToken(tokens[0],"contourLineSpacing"))
    	{
    		if(tokens.size()==2)
    			{
    			try
    				{
    				contourLineSpacing=atof(tokens[1].c_str());
    				if(contourLineSpacing!=0)
    					{
    					/* Update all height color maps: */
    					for(std::vector<RenderSettings>::iterator rsIt=renderSettings.begin();rsIt!=renderSettings.end();++rsIt)
    						{
    							if(rsIt->useContourLines=true)
    								rsIt->contourLineSpacing=GLfloat(contourLineSpacing);
    								rsIt->surfaceRenderer->setContourLineDistance(rsIt->contourLineSpacing);
    						}
    					}                                
    				}
    			catch(const std::runtime_error& err)
    				{
    				std::cerr<<"Cannot read contour line spacing "<<tokens[1]<<" due to exception "<<err.what()<<std::endl;
    				}
    			}
    		else
    			std::cerr<<"Wrong number of arguments for contourLineSpacing control pipe command"<<std::endl;	
    	}
    // --Modification to enable contour line spacing through control pipe
    // ++Modification to enable contour lines through control pipe
    else if(isToken(tokens[0],"useContourLines"))
    	{
    		if(tokens.size()==2)
    			{
    			try
    				{
    				/* Update all height color maps: */
    				for(std::vector<RenderSettings>::iterator rsIt=renderSettings.begin();rsIt!=renderSettings.end();++rsIt)
    					{
    					useContourLine = atoi(tokens[1].c_str());
    					if(useContourLine==0)
    						{									        
    							rsIt->useContourLines=false;
    							rsIt->surfaceRenderer->setDrawContourLines(rsIt->useContourLines);
    						}
    					else if(useContourLine==1)
    						{								        
    							rsIt->useContourLines=true;
    							rsIt->surfaceRenderer->setDrawContourLines(rsIt->useContourLines);
    						}
    					else
    						std::cerr<<"Invalid argument value for useContourLines control pipe command"<<std::endl;	
    					}
    				}
    			catch(const std::runtime_error& err)
    				{
    				std::cerr<<"Cannot read contour line spacing "<<tokens[1]<<" due to exception "<<err.what()<<std::endl;
    				}
    			}
    		else
    			std::cerr<<"Wrong number of arguments for contourLineSpacing control pipe command"<<std::endl;	
    	}
    // --Modification to enable contour lines through control pipe
    
    #118392

    Oliver Kreylos
    Keymaster

    Nice job!

    Minor source code critique:

    contourLineSpacing and useCountourLine should not be elements of class Sandbox; they should be local variables of their respective code branches inside the control pipe handling code inside the frame() method. There’s no need to modify Sandbox.h.

    In the contourLineSpacing block: Read from the second token into a local variable of type GLfloat, then there’s no need to cast to GLfloat later. You don’t need to check if contour lines are enabled before setting their distance; if they’re disabled, the surfaceRenderer will ignore the distance setting. This will come in handy later when you globally enable contour lines on renderers that might have had them disabled before. You don’t necessarily have to set the contour line distance in the RenderSettings structure itself; those values are only used to store command line options before the surfaceRenderer is created. No need to wrap the code into a try/catch block; none of the methods called in the block can throw exceptions.

    In the useContourLines block: similar basic comments to above. In addition, I advise against using integers to encode boolean values at textual interfaces. Instead of parsing the second token into an int and comparing that int to 0 or 1, directly compare the second token to “on” and “off” using, e.g., isToken(tokens[1],”on”) and act accordingly. That way the command pipe syntax is in line with other boolean-value commands such as “dippingBed off.”

    I.e., I would do

    else if(isToken(tokens[0],"useContourLines"))
      {
      if(tokens.size()==2)
        {
        /* Parse the command parameter: */
        bool useContourLines=isToken(tokens[1],"on");
        if(useContourLines||isToken(tokens[1],"off"))
          {
          /* Enable or disable contour lines on all surface renderers: */
          for(std::vector<RenderSettings>::iterator rsIt=renderSettings.begin();rsIt!=renderSettings.end();++rsIt)
            rsIt->surfaceRenderer->setDrawContourLines(useContourLines);
          }
        else
          std::cerr<<"Invalid parameter "<<tokens[1]<<" for useContourLines control pipe command"<<std::endl;
        }
      else
        std::cerr<<"Wrong number of arguments for useContourLines control pipe command"<<std::endl;
      }
    else if(isToken(tokens[0],"contourLineSpacing"))
      {
      if(tokens.size()==2)
        {
        /* Parse the contour line distance: */
        GLfloat contourLineSpacing=GLfloat(atof(tokens[1].c_str()));
        
        /* Check if the requested spacing is valid: */
        if(contourLineSpacing>0.0f)
          {
          /* Override the contour line spacing of all surface renderers: */
          for(std::vector<RenderSettings>::iterator rsIt=renderSettings.begin();rsIt!=renderSettings.end();++rsIt)
            rsIt->surfaceRenderer->setContourLineDistance(contourLineSpacing);
          }
        else
          std::cerr<<"Invalid parameter "<<contourLineSpacing<<" for contourLineSpacing control pipe command"<<std::endl;
        }
      else
        std::cerr<<"Wrong number of arguments for contourLineSpacing control pipe command"<<std::endl;
      }
    • This reply was modified 2 months, 1 week ago by  Oliver Kreylos. Reason: Improved parsing of useContourLines command
    • This reply was modified 2 months, 1 week ago by  Oliver Kreylos. Reason: Typo!
    #118395

    paguy
    Participant

    Thanks Oliver. great work in producing the sandbox in the first place. Its been a little while since I coded c++, last coding task was VB(shudder) and PowerShell, so it took me a little while to debug my use of an assignment operator rather than a comparison operator, so I was just happy it worked. Happy to have your feedback, consistent code is a good thing.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

Comments are closed.