<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.3//EN" "https://www.web3d.org/specifications/x3d-3.3.dtd">
<X3D profile='Immersive' version='3.3 xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance' xsd:noNamespaceSchemaLocation =' https://www.web3d.org/specifications/x3d-3.3.xsd '>
<head>
<meta name='titlecontent='SideScanSonarPrototype.x3d'/>
<meta name='descriptioncontent='Produce wireframe or transparent sidescan sonar beams.'/>
<meta name='creatorcontent='Don Brutzman'/>
<meta name='createdcontent='15 March 2001'/>
<meta name='modifiedcontent='20 October 2019'/>
<meta name='identifiercontent=' https://savage.nps.edu/Savage/CommunicationsAndSensors/Sonar/SideScanSonarPrototype.x3d '/>
<meta name='generatorcontent='X3D-Edit 3.3, https://savage.nps.edu/X3D-Edit'/>
<meta name='licensecontent=' ../../license.html'/>
</head>
<!--

Index for ProtoDeclare definition : SideScanSonar

Index for DEF nodes : BEAM_CALCULATE, BEAM_CONTROL, BeamPatternCoordinatePoints, DETECTION, FaceMaterial, IFS, ILS, LockedDownInterface2D, SOLID_SWITCH, WIREFRAME_SWITCH, WireMaterial

Index for Viewpoint image : Viewpoint_1
-->
<Scene>
<NavigationInfo DEF='LockedDownInterface2Dtype='"NONE"'/>
<Background skyColor='0 0.3 0.5'/>
<WorldInfo info='"Produce wireframe or transparent beam cones."title='BeamCone Prototyupe'/>
<Viewpoint description='SideScanSonar Prototypeposition='0 0 15'/>
<ProtoDeclare name='SideScanSonarappinfo='Produce wireframe or semi-transparent sonar sidescan beams'>
<ProtoInterface>
<field name='altitudetype='SFFloataccessType='inputOnly'
 appinfo='vertical distance above bottom in meters along y axis'/>

<field name='defaultAltitudetype='SFFloatvalue='3accessType='initializeOnly'
 appinfo='default vertical distance above bottom in meters along y axis'/>

<field name='maxAltitudetype='SFFloatvalue='3accessType='initializeOnly'
 appinfo='maximum effective altitude of sidescan sonar above bottom'/>

<field name='defaultCrossTrackHalfRangetype='SFFloatvalue='30accessType='initializeOnly'
 appinfo='distance in meters from nadir to rightmost/leftmost edge when operating at defaultAltitude above the bottom'/>

<field name='defaultTrackWidthMeterstype='SFFloatvalue='0.30accessType='initializeOnly'
 appinfo='longitudinal width of a single return'/>

<field name='vehicleWidthMeterstype='SFFloatvalue='0.178accessType='initializeOnly'
 appinfo='width (or diameter) of vehicle carrying port/starboard sidescan sonar transducers'/>

<field name='contacttype='SFBoolaccessType='inputOnly'
 appinfo='(communications) whether transmitted signal is in contact with receiver or (sensor) is a target return detected?'/>

<field name='wireframetype='SFBoolvalue='trueaccessType='initializeOnly'
 appinfo='draw lines for tracking shape?'/>

<field name='solidtype='SFBoolvalue='trueaccessType='initializeOnly'
 appinfo='draw solid tracking shape?'/>

<field name='contactColortype='SFColorvalue='.8 .1 .1accessType='initializeOnly'
 appinfo='rendering color when contact=true'/>

<field name='noContactColortype='SFColorvalue='.3 .5 .5accessType='initializeOnly'
 appinfo='rendering color when contact=false'/>

<field name='transparencytype='SFFloatvalue='0accessType='inputOutput'
 appinfo='1 = fully transparent wireframe only'/>
</ProtoInterface>
<ProtoBody>
<!-- BEAM_CONTROL beam scaling is controlled by range/beamHeightDegrees/beamWidthDegrees/direction inputs -->
<!-- ROUTE information for BEAM_CONTROL node:  [from BEAM_CALCULATE.beamScale to scale ] -->
<Transform DEF='BEAM_CONTROL'>
<!-- ROUTE information for WIREFRAME_SWITCH node:  [from DETECTION.wireframeChoice to whichChoice ] -->
<Switch DEF='WIREFRAME_SWITCHwhichChoice='1'>
<!-- TODO refactor index values starting from -1, remove WorldInfo -->
<WorldInfo info='"initial choice is null node (WorldInfo), meaning no wireframe beam"'/>
<Shape>
<Appearance>
<!-- ROUTE information for WireMaterial node:  [from DETECTION.beamColor to emissiveColor ] -->
<Material DEF='WireMaterialdiffuseColor='.1 .1 .1emissiveColor='.1 .1 .1'>
<IS>
<connect nodeField='transparencyprotoField='transparency'/>
</IS>
</Material>
</Appearance>
<IndexedLineSet DEF='ILScoordIndex='1 2 3 1 -1 5 3 4 5 -1 6 8 7 6 -1 10 9 8 10 -1 6 7 2 1 6 -1 10 5 4 9 10 -1'>
<!-- ROUTE information for BeamPatternCoordinatePoints node:  [from BEAM_CALCULATE.coordinatePoints to point ] -->
<Coordinate DEF='BeamPatternCoordinatePointspoint='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0'/>
</IndexedLineSet>
</Shape>
</Switch>
<!-- ROUTE information for SOLID_SWITCH node:  [from DETECTION.solidChoice to whichChoice ] -->
<Switch DEF='SOLID_SWITCHwhichChoice='0'>
<!-- TODO refactor index values starting from -1, remove WorldInfo -->
<WorldInfo info='"initial choice is null node (WorldInfo), meaning no solid beam"'/>
<Shape>
<Appearance>
<!-- ROUTE information for FaceMaterial node:  [from DETECTION.beamColor to emissiveColor ] -->
<Material DEF='FaceMaterialdiffuseColor='.1 .1 .1'>
<IS>
<connect nodeField='transparencyprotoField='transparency'/>
</IS>
</Material>
</Appearance>
<IndexedFaceSet DEF='IFSsolid='falsecoordIndex='1 2 3 1 -1 5 3 4 5 -1 6 8 7 6 -1 10 9 8 10 -1 6 7 2 1 6 -1 10 5 4 9 10 -1'>
<Coordinate USE='BeamPatternCoordinatePoints'/>
</IndexedFaceSet>
</Shape>
</Switch>
</Transform>
<!-- Non-renderable animation controls -->
<!-- ROUTE information for BEAM_CALCULATE node:  [from beamScale to BEAM_CONTROL.scale ] [from coordinatePoints to BeamPatternCoordinatePoints.point ] -->
<Script DEF='BEAM_CALCULATE'>
<field name='altitudetype='SFFloataccessType='inputOnly'/>
<field name='defaultAltitudetype='SFFloataccessType='initializeOnly'/>
<field name='maxAltitudetype='SFFloataccessType='initializeOnly'/>
<field name='defaultCrossTrackHalfRangetype='SFFloataccessType='initializeOnly'/>
<field name='defaultTrackWidthMeterstype='SFFloataccessType='initializeOnly'/>
<field name='vehicleWidthMeterstype='SFFloataccessType='initializeOnly'/>
<field name='beamScaletype='SFVec3faccessType='outputOnly'/>
<field name='coordinatePointstype='MFVec3faccessType='outputOnly'/>
<field name='traceEnabledtype='SFBoolvalue='falseaccessType='initializeOnly'
 appinfo='internal flag to turn on Script tracing'/>

<IS>
<connect nodeField='altitudeprotoField='altitude'/>
<connect nodeField='defaultAltitudeprotoField='defaultAltitude'/>
<connect nodeField='maxAltitudeprotoField='maxAltitude'/>
<connect nodeField='defaultCrossTrackHalfRangeprotoField='defaultCrossTrackHalfRange'/>
<connect nodeField='defaultTrackWidthMetersprotoField='defaultTrackWidthMeters'/>
<connect nodeField='vehicleWidthMetersprotoField='vehicleWidthMeters'/>
</IS>
<![CDATA[
          
ecmascript:

function tracePrint (value)
{
	if (traceEnabled) Browser.print ('[SideScanSonar BEAM_CALCULATE] ' + value);
}

function initialize () {
 beamScale = new SFVec3f (1, 1, 1);
 dt2 = defaultTrackWidthMeters/2;

 origin = new SFVec3f (0, 0, 0);
 a  = new SFVec3f (-dt2,  0,               -vehicleWidthMeters/2);
 b  = new SFVec3f (-dt2, -defaultAltitude, -defaultCrossTrackHalfRange);
 c  = new SFVec3f (-dt2, -defaultAltitude,  0);
 d  = new SFVec3f (-dt2, -defaultAltitude,  defaultCrossTrackHalfRange);
 e  = new SFVec3f (-dt2,  0,                vehicleWidthMeters/2);
 aa = new SFVec3f ( dt2,  0,               -vehicleWidthMeters/2);
 bb = new SFVec3f ( dt2, -defaultAltitude, -defaultCrossTrackHalfRange);
 cc = new SFVec3f ( dt2, -defaultAltitude,  0);
 dd = new SFVec3f ( dt2, -defaultAltitude,  defaultCrossTrackHalfRange);
 ee = new SFVec3f ( dt2,  0,                vehicleWidthMeters/2);

 coordinatePoints = new MFVec3f (origin, a, b, c, d, e, aa, bb, cc, dd, ee);

 tracePrint ('coordinatePoints =' + coordinatePoints);
}
function altitude (newAltitude, timeStamp) {
 if (newAltitude <= 0)
 {
   beamHeightFactor= 0.001;
   beamScale = new SFVec3f (1, beamHeightFactor, beamHeightFactor);
 }
 else if (newAltitude < maxAltitude)
 {
   beamHeightFactor= newAltitude / defaultAltitude;
   beamScale = new SFVec3f (1, beamHeightFactor, beamHeightFactor);
 }
 else
 {
   beamHeightFactor= maxAltitude / defaultAltitude;
   beamScale = new SFVec3f (1, beamHeightFactor, beamHeightFactor);
 }
 tracePrint ('newAltitude      =' + newAltitude);
 tracePrint ('beamHeightFactor =' + beamHeightFactor);
 tracePrint ('beamScale        =' + beamScale);
}

        
]]>
</Script>
<!-- ROUTE information for DETECTION node:  [from beamColor to WireMaterial.emissiveColor ] [from beamColor to FaceMaterial.emissiveColor ] [from wireframeChoice to WIREFRAME_SWITCH.whichChoice ] [from solidChoice to SOLID_SWITCH.whichChoice ] -->
<Script DEF='DETECTIONdirectOutput='true'>
<field name='contacttype='SFBoolaccessType='inputOnly'/>
<field name='wireframetype='SFBoolaccessType='initializeOnly'/>
<field name='solidtype='SFBoolaccessType='initializeOnly'/>
<field name='contactColortype='SFColoraccessType='initializeOnly'/>
<field name='noContactColortype='SFColoraccessType='initializeOnly'/>
<field name='beamColortype='SFColoraccessType='outputOnly'/>
<field name='wireframeChoicetype='SFInt32accessType='outputOnly'/>
<field name='solidChoicetype='SFInt32accessType='outputOnly'/>
<field name='MaterialNodeHoldertype='SFNodeaccessType='initializeOnly'>
<Material USE='FaceMaterial'/>
</field>
<field name='traceEnabledtype='SFBoolvalue='falseaccessType='initializeOnly'
 appinfo='internal flag to turn on Script tracing'/>

<IS>
<connect nodeField='contactprotoField='contact'/>
<connect nodeField='wireframeprotoField='wireframe'/>
<connect nodeField='solidprotoField='solid'/>
<connect nodeField='contactColorprotoField='contactColor'/>
<connect nodeField='noContactColorprotoField='noContactColor'/>
</IS>
<![CDATA[
          
ecmascript:

function tracePrint (value)
{
	if (traceEnabled) Browser.print ('[SideScanSonar DETECTION] ' + value);
}

function initialize ()
{
	beamColor = noContactColor;
	if (wireframe == true) wireframeChoice = 1;
	if (solid     == true) solidChoice     = 1;

	// Debug  statements
	tracePrint ('  wireframe       =' + wireframe);
	tracePrint ('  solid           =' + solid);
	tracePrint ('  contactColor    =' + contactColor);
	tracePrint ('  noContactColor  =' + noContactColor);
	tracePrint ('  beamColor       =' + beamColor);
	tracePrint ('  wireframeChoice =' + wireframeChoice);
	tracePrint ('  solidChoice     =' + solidChoice);
	tracePrint ('  transparency    =' + MaterialNodeHolder.transparency);
}
function contact (newDetect, timeStamp)
{
	tracePrint ('  newDetect       =' + newDetect);
	if (newDetect) beamColor = contactColor;
	else           beamColor = noContactColor;
}

        
]]>
</Script>
<ROUTE fromNode='BEAM_CALCULATEfromField='beamScaletoNode='BEAM_CONTROLtoField='scale'/>
<ROUTE fromNode='BEAM_CALCULATEfromField='coordinatePointstoNode='BeamPatternCoordinatePointstoField='point'/>
<ROUTE fromNode='DETECTIONfromField='beamColortoNode='WireMaterialtoField='emissiveColor'/>
<ROUTE fromNode='DETECTIONfromField='beamColortoNode='FaceMaterialtoField='emissiveColor'/>
<ROUTE fromNode='DETECTIONfromField='wireframeChoicetoNode='WIREFRAME_SWITCHtoField='whichChoice'/>
<ROUTE fromNode='DETECTIONfromField='solidChoicetoNode='SOLID_SWITCHtoField='whichChoice'/>
</ProtoBody>
</ProtoDeclare>
<!-- Viewable geometry for this scene is anchored text that links to an example showing ExternProtoDeclare usage of BeamCone -->
<Anchor description='SideScanSonar Exampleparameter='"target=_blank"'
  url=' "SideScanSonarExample.x3d" "https://savage.nps.edu/Savage/CommunicationsAndSensors/Sonar/SideScanSonarExample.x3d" "SideScanSonarExample.wrl" "https://savage.nps.edu/Savage/CommunicationsAndSensors/Sonar/SideScanSonarExample.wrl" '>
<Shape>
<Appearance>
<Material diffuseColor='0 1 1emissiveColor='0 1 1'/>
</Appearance>
<Text string='"SideScanSonarPrototype" "is a Prototype definition file." "" "To see an example scene" "click this text and view" "SideScanSonarExample."'>
<FontStyle justify='"MIDDLE" "MIDDLE"'/>
</Text>
</Shape>
<Shape>
<!-- transparent Box as text-selection assist -->
<Box size='10.5 6 .001'/>
<Appearance>
<Material transparency='1'/>
</Appearance>
</Shape>
</Anchor>
</Scene>
</X3D>
<!--

Index for ProtoDeclare definition : SideScanSonar

Index for DEF nodes : BEAM_CALCULATE, BEAM_CONTROL, BeamPatternCoordinatePoints, DETECTION, FaceMaterial, IFS, ILS, LockedDownInterface2D, SOLID_SWITCH, WIREFRAME_SWITCH, WireMaterial

Index for Viewpoint image : Viewpoint_1
-->

<!-- Color key: <X3dNode DEF='idName' field='value'/> matches <XmlElement DEF='idName' attribute='value'/>
(Light blue background: behavior node) (Grey background: inserted documentation) (Magenta background: X3D Extensibility)
    <Prototype name='ProtoName'> <field name='fieldName'/> </Prototype> -->

<!-- For additional help information about X3D scenes, please see X3D Tooltips, X3D Resources and X3D Scene Authoring Hints. -->