void setNodeData(SetLiveState s) { super.setNodeData(s); if (!inSharedGroup) { int size = s.changedViewGroup.size(); if (s.keyList.length < size + 1) { int[] newKeyList = new int[s.keyList.length + 20]; System.arraycopy(s.keyList, 0, newKeyList, 0, s.keyList.length); s.keyList = newKeyList; // System.err.println("====> setNodeData: Allocating Non-shared"); } setAuxData(s, 0, 0); } else { // For inSharedGroup case. int j, hkIndex; int size = s.changedViewGroup.size(); if (s.keyList.length < size + 1 + s.keys.length) { int[] newKeyList = new int[s.keyList.length + s.keys.length + 20]; System.arraycopy(s.keyList, 0, newKeyList, 0, s.keyList.length); s.keyList = newKeyList; // System.err.println("====> setNodeData: Allocating Shared"); } for (j = 0; j < s.keys.length; j++) { hkIndex = s.keys[j].equals(localToVworldKeys, 0, localToVworldKeys.length); if (hkIndex >= 0) { setAuxData(s, j, hkIndex); } else { MasterControl.getCoreLogger().severe("Can't Find matching hashKey in setNodeData."); } } } // Make the VSG's viewLists as the relavant one for its children s.viewLists = viewLists; }
/** remove the localToVworld transform for a node. */ @Override void removeNodeData(SetLiveState s) { ArrayList switchTargets; int i, j; if (refCount <= 0) { localToVworld = null; localToVworldIndex = null; localToVworldKeys = null; // restore to default and avoid calling clear() // that may clear parent reference branchGroupPaths // Note that this function did not invoke super.removeNodeData() branchGroupPaths = new ArrayList<BranchGroupRetained[]>(1); orderedPaths = null; switchStates = null; cachedTargets = null; targetThreads = 0; lights.clear(); fogs.clear(); modelClips.clear(); altAppearances.clear(); } else { int index, len; // Remove the localToVworld key int newLen = localToVworld.length - s.keys.length; Transform3D[][] newTList = new Transform3D[newLen][]; HashKey[] newHList = new HashKey[newLen]; Transform3D newChildTList[][] = null; int[][] newIndexList = new int[newLen][]; CachedTargets[] newTargets = new CachedTargets[newLen]; int[] tempIndex = new int[s.keys.length]; int curStart = 0, newStart = 0; boolean found = false; for (i = 0; i < s.keys.length; i++) { index = s.keys[i].equals(localToVworldKeys, 0, localToVworldKeys.length); tempIndex[i] = index; if (index >= 0) { found = true; if (index == curStart) { curStart++; } else { len = index - curStart; System.arraycopy(localToVworld, curStart, newTList, newStart, len); System.arraycopy(localToVworldIndex, curStart, newIndexList, newStart, len); System.arraycopy(localToVworldKeys, curStart, newHList, newStart, len); System.arraycopy(cachedTargets, curStart, newTargets, newStart, len); curStart = index + 1; newStart = newStart + len; } } else { found = false; MasterControl.getCoreLogger().severe("Can't Find matching hashKey in SG.removeNodeData."); } } if ((found == true) && (curStart < localToVworld.length)) { len = localToVworld.length - curStart; System.arraycopy(localToVworld, curStart, newTList, newStart, len); System.arraycopy(localToVworldIndex, curStart, newIndexList, newStart, len); System.arraycopy(localToVworldKeys, curStart, newHList, newStart, len); System.arraycopy(cachedTargets, curStart, newTargets, newStart, len); } // Must be in reverse, to preserve right indexing. for (i = tempIndex.length - 1; i >= 0; i--) { if (tempIndex[i] >= 0) { branchGroupPaths.remove(tempIndex[i]); orderedPaths.remove(tempIndex[i]); switchStates.remove(tempIndex[i]); lights.remove(tempIndex[i]); fogs.remove(tempIndex[i]); modelClips.remove(tempIndex[i]); altAppearances.remove(tempIndex[i]); } } localToVworld = newTList; localToVworldIndex = newIndexList; localToVworldKeys = newHList; cachedTargets = newTargets; } s.localToVworld = localToVworld; s.localToVworldIndex = localToVworldIndex; s.localToVworldKeys = localToVworldKeys; s.orderedPaths = orderedPaths; s.switchStates = switchStates; s.viewLists = viewLists; s.lights = lights; s.fogs = fogs; s.modelClips = modelClips; s.altAppearances = altAppearances; }
@Override void setNodeData(SetLiveState s) { // For inSharedGroup case. int i, j, len; if (localToVworld == null) { localToVworld = new Transform3D[s.keys.length][]; localToVworldIndex = new int[s.keys.length][]; localToVworldKeys = new HashKey[s.keys.length]; cachedTargets = new CachedTargets[s.keys.length]; len = 0; } else { int newLen = localToVworld.length + s.keys.length; Transform3D newTList[][] = new Transform3D[newLen][]; HashKey newHList[] = new HashKey[newLen]; int newIndexList[][] = new int[newLen][]; CachedTargets newTargets[] = new CachedTargets[newLen]; len = localToVworld.length; // Copy the existing data into the newly created data objects. System.arraycopy(localToVworld, 0, newTList, 0, localToVworld.length); System.arraycopy(localToVworldIndex, 0, newIndexList, 0, localToVworldIndex.length); System.arraycopy(localToVworldKeys, 0, newHList, 0, localToVworldKeys.length); System.arraycopy(cachedTargets, 0, newTargets, 0, cachedTargets.length); localToVworld = newTList; localToVworldIndex = newIndexList; localToVworldKeys = newHList; cachedTargets = newTargets; } int[] hkIndex = new int[1]; int hkIndexPlus1, blkSize; s.hashkeyIndex = new int[s.keys.length]; // This should appear before super.setNodeData() if it exists s.parentBranchGroupPaths = branchGroupPaths; for (i = len, j = 0; i < localToVworld.length; i++, j++) { if (s.keys[j].equals(localToVworldKeys, hkIndex, 0, i)) { MasterControl.getCoreLogger().severe("Found matching hashKey in setNodeData."); } s.hashkeyIndex[j] = hkIndex[0]; if (hkIndex[0] == i) { // Append to last. localToVworldKeys[i] = s.keys[j]; localToVworld[i] = s.currentTransforms[j]; localToVworldIndex[i] = s.currentTransformsIndex[j]; } else { // Insert in between array elements. hkIndexPlus1 = hkIndex[0] + 1; blkSize = i - hkIndex[0]; // Shift the later portion of array elements by one position. // This is the make room for the new data entry. System.arraycopy(localToVworldKeys, hkIndex[0], localToVworldKeys, hkIndexPlus1, blkSize); System.arraycopy(localToVworld, hkIndex[0], localToVworld, hkIndexPlus1, blkSize); System.arraycopy(localToVworldIndex, hkIndex[0], localToVworldIndex, hkIndexPlus1, blkSize); System.arraycopy(cachedTargets, hkIndex[0], cachedTargets, hkIndexPlus1, blkSize); localToVworldKeys[hkIndex[0]] = s.keys[j]; localToVworld[hkIndex[0]] = s.currentTransforms[j]; localToVworldIndex[hkIndex[0]] = s.currentTransformsIndex[j]; } // System.err.println("SG: j = "+j+" hkIndex[0] = "+hkIndex[0]+" s.keys[j] = "+s.keys[j]); // For now (1.2.1beta2) only. We cleanup setLive, and clearLive in // next release. setAuxData(s, j, hkIndex[0]); } // The SetLiveState need the reflect the new state of this SharedGroup. // The SetLiveState will get reset back in SetLive, after all children of this // node have been set live. s.localToVworld = localToVworld; s.localToVworldIndex = localToVworldIndex; s.localToVworldKeys = localToVworldKeys; s.orderedPaths = orderedPaths; s.switchStates = switchStates; // Note that s.childSwitchLinks is updated in super.setLive s.childTransformLinks = childTransformLinks; s.parentTransformLink = this; s.parentSwitchLink = this; s.viewLists = viewLists; s.lights = lights; s.fogs = fogs; s.altAppearances = altAppearances; s.modelClips = modelClips; }
/** remove the localToVworld transform for a transformGroup */ void removeNodeData(SetLiveState s) { synchronized (this) { // synchronized with TransformStructure if (refCount <= 0) { childLocalToVworld = null; childLocalToVworldIndex = null; transformLevels = null; // only use by TransformStruct. cachedTargets = null; perPathData = null; targetThreads = 0; if (parentTransformLink != null) { ArrayList obj; if (parentTransformLink instanceof TransformGroupRetained) { obj = ((TransformGroupRetained) parentTransformLink).childTransformLinks; } else { obj = ((SharedGroupRetained) parentTransformLink).childTransformLinks; } synchronized (obj) { obj.remove(this); } } aboveAViewPlatform = false; } else { int i, index, len; // Remove the localToVworld key int newLen = localToVworld.length - s.keys.length; Transform3D[][] newChildTList = new Transform3D[newLen][]; int[][] newChildIndexList = new int[newLen][]; int[] newTransformLevels = new int[newLen]; ArrayList[] newChildPTG = new ArrayList[newLen]; CachedTargets[] newTargets = new CachedTargets[newLen]; TransformGroupData[] newPerPathData = new TransformGroupData[newLen]; int[] tempIndex = new int[s.keys.length]; int curStart = 0, newStart = 0; boolean found = false; for (i = 0; i < s.keys.length; i++) { index = s.keys[i].equals(localToVworldKeys, 0, localToVworldKeys.length); tempIndex[i] = index; if (index >= 0) { found = true; if (index == curStart) { curStart++; } else { len = index - curStart; System.arraycopy(childLocalToVworld, curStart, newChildTList, newStart, len); System.arraycopy(childLocalToVworldIndex, curStart, newChildIndexList, newStart, len); System.arraycopy(transformLevels, curStart, newTransformLevels, newStart, len); System.arraycopy(cachedTargets, curStart, newTargets, newStart, len); System.arraycopy(perPathData, curStart, newPerPathData, newStart, len); curStart = index + 1; newStart = newStart + len; } } else { found = false; MasterControl.getCoreLogger().severe("TG.removeNodeData-Can't find matching hashKey."); } } if ((found == true) && (curStart < localToVworld.length)) { len = localToVworld.length - curStart; System.arraycopy(childLocalToVworld, curStart, newChildTList, newStart, len); System.arraycopy(childLocalToVworldIndex, curStart, newChildIndexList, newStart, len); System.arraycopy(transformLevels, curStart, newTransformLevels, newStart, len); System.arraycopy(cachedTargets, curStart, newTargets, newStart, len); System.arraycopy(perPathData, curStart, newPerPathData, newStart, len); } childLocalToVworld = newChildTList; childLocalToVworldIndex = newChildIndexList; transformLevels = newTransformLevels; cachedTargets = newTargets; perPathData = newPerPathData; } super.removeNodeData(s); // Set it back to its parent localToVworld data. // This is b/c the parent has changed it localToVworld data arrays. s.localToVworld = childLocalToVworld; s.localToVworldIndex = childLocalToVworldIndex; } }
// synchronized with TransformStructure synchronized void setNodeData(SetLiveState s) { int i; super.setNodeData(s); childTrans = new Transform3D[s.currentTransforms.length][2]; childTransIndex = new int[s.currentTransforms.length][2]; for (i = 0; i < s.currentTransforms.length; i++) { childTrans[i][0] = new Transform3D(); childTrans[i][0].mul( s.currentTransforms[i][s.currentTransformsIndex[i][CURRENT_LOCAL_TO_VWORLD]], currentTransform); childTrans[i][1] = new Transform3D(childTrans[i][0]); childTransIndex[i][0] = 0; childTransIndex[i][1] = 0; } if (!s.inSharedGroup) { s.transformLevels[0] += 1; maxTransformLevel = s.transformLevels[0]; } else { for (i = 0; i < s.keys.length; i++) { s.transformLevels[i] += 1; if (s.transformLevels[i] > maxTransformLevel) { maxTransformLevel = s.transformLevels[i]; } } } if (!inSharedGroup) { if (childLocalToVworld == null) { // If the node is a transformGroup then need to keep // the child transforms as well childLocalToVworld = new Transform3D[1][]; childLocalToVworldIndex = new int[1][]; transformLevels = new int[1]; // Use by TransformStructure cachedTargets = new CachedTargets[1]; perPathData = new TransformGroupData[1]; } childLocalToVworld[0] = childTrans[0]; childLocalToVworldIndex[0] = childTransIndex[0]; transformLevels[0] = s.transformLevels[0]; setAuxData(s, 0, 0); } else { // For inSharedGroup case. int j, len; if (childLocalToVworld == null) { childLocalToVworld = new Transform3D[s.keys.length][]; childLocalToVworldIndex = new int[s.keys.length][]; transformLevels = new int[s.keys.length]; cachedTargets = new CachedTargets[s.keys.length]; perPathData = new TransformGroupData[s.keys.length]; len = 0; } else { len = localToVworld.length - s.keys.length; int newLen = localToVworld.length; Transform3D newChildTList[][] = new Transform3D[newLen][]; int newChildIndexList[][] = new int[newLen][]; int newTransformLevels[] = new int[newLen]; CachedTargets newTargets[] = new CachedTargets[newLen]; TransformGroupData newPerPathData[] = new TransformGroupData[newLen]; System.arraycopy(childLocalToVworld, 0, newChildTList, 0, childLocalToVworld.length); System.arraycopy( childLocalToVworldIndex, 0, newChildIndexList, 0, childLocalToVworldIndex.length); System.arraycopy(transformLevels, 0, newTransformLevels, 0, transformLevels.length); System.arraycopy(cachedTargets, 0, newTargets, 0, cachedTargets.length); System.arraycopy(perPathData, 0, newPerPathData, 0, perPathData.length); childLocalToVworld = newChildTList; childLocalToVworldIndex = newChildIndexList; transformLevels = newTransformLevels; cachedTargets = newTargets; perPathData = newPerPathData; } int hkIndex; int hkIndexPlus1, blkSize; for (i = len, j = 0; i < localToVworld.length; i++, j++) { hkIndex = s.keys[j].equals(localToVworldKeys, 0, localToVworldKeys.length); if (hkIndex < 0) { MasterControl.getCoreLogger().severe("Can't Find matching hashKey in setNodeData."); break; } else if (hkIndex >= i) { // Append to last. childLocalToVworld[i] = childTrans[j]; childLocalToVworldIndex[i] = childTransIndex[j]; transformLevels[i] = s.transformLevels[j]; } else { hkIndexPlus1 = hkIndex + 1; blkSize = i - hkIndex; System.arraycopy(childLocalToVworld, hkIndex, childLocalToVworld, hkIndexPlus1, blkSize); System.arraycopy( childLocalToVworldIndex, hkIndex, childLocalToVworldIndex, hkIndexPlus1, blkSize); System.arraycopy(transformLevels, hkIndex, transformLevels, hkIndexPlus1, blkSize); System.arraycopy(cachedTargets, hkIndex, cachedTargets, hkIndexPlus1, blkSize); System.arraycopy(perPathData, hkIndex, perPathData, hkIndexPlus1, blkSize); childLocalToVworld[hkIndex] = childTrans[j]; childLocalToVworldIndex[hkIndex] = childTransIndex[j]; transformLevels[hkIndex] = s.transformLevels[j]; } setAuxData(s, j, hkIndex); } } if (s.childTransformLinks != null) { // do not duplicate shared nodes synchronized (s.childTransformLinks) { if (!inSharedGroup || !s.childTransformLinks.contains(this)) { s.childTransformLinks.add(this); } } } s.localToVworld = childLocalToVworld; s.localToVworldIndex = childLocalToVworldIndex; s.currentTransforms = childTrans; s.currentTransformsIndex = childTransIndex; s.childTransformLinks = childTransformLinks; s.parentTransformLink = this; }