12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Threading;
- using System.Windows;
- using System.Windows.Threading;
- using UtilityService;
- using Vinno.DataManager.Data;
- using Vinno.DataManager.Infrastructure;
- using Vinno.DataManager.Infrastructure.Interfaces;
- using Vinno.DataManager.Utilities;
- using Vinno.DataTypes;
- using Vinno.Enums;
- using Vinno.Infrastructure;
- using Vinno.Infrastructure.Enums;
- using Vinno.Infrastructure.Interfaces;
- using Vinno.Infrastructure.Utilities;
- using Vinno.Models.Base;
- using Vinno.Models.Base.Modes;
- using Vinno.Models.Base.Parameters;
- using Vinno.Models.Base.VisualAreas;
- using Vinno.Models.Base.Visuals;
- using Vinno.Models.Dicom.Replay.Modes;
- using Vinno.Models.SpecificImpl.Modes;
- using Vinno.Modules.MeasureModule.Calculators;
- using Vinno.Modules.MeasureModule.ItemMetas;
- using Vinno.Modules.MeasureModule.Items;
- using Vinno.Modules.MeasureModule.Results;
- using Vinno.Modules.RenderModule;
- using Vinno.Services.InputServices;
- using Vinno.Services.MessageService;
- using Vinno.Utilities;
- using Vinno.vCloud.Report.JsonConverters;
- namespace Vinno.Modules.MeasureModule.Primitives.SRMeasure
- {
- public static class SRPointTrans
- {
- //Scream Point To ImgPoint
- public static DPoint TransPointS2I(DPoint srcPoint, double roundw, double roundh, double urmw, double urmh, int datew, int dateh, bool limit = true)
- {
- double Scalarx = (double) datew / urmw;
- double Scalary = (double) dateh / urmh;
- DPoint urmzeroPoint=new DPoint(-urmw/2,(roundh- urmh) /2);
- DPoint outPoint = new DPoint((srcPoint.X - urmzeroPoint.X) * Scalarx,
- (srcPoint.Y - urmzeroPoint.Y) * Scalary);
- if (limit)
- {
- if (outPoint.X < 0)
- outPoint.X = 0;
- if (outPoint.X > (datew - 1))
- outPoint.X = datew - 1;
- if (outPoint.Y < 0)
- outPoint.Y = 0;
- if (outPoint.Y > (dateh - 1))
- outPoint.Y = dateh - 1;
- }
- return outPoint;
- }
- //Scream Point To ImgPoint
- public static DPoint TransPointI2S(DPoint srcPoint, double roundw, double roundh, double urmw, double urmh, int datew, int dateh)
- {
- double Scalarx = (double)urmw/ datew;
- double Scalary = (double) urmh/ dateh ;
- DPoint urmzeroPoint = new DPoint(-urmw / 2, (roundh - urmh) / 2);
- DPoint outPoint = new DPoint(srcPoint.X * Scalarx+ urmzeroPoint.X, srcPoint.Y * Scalary + urmzeroPoint.Y);
- return outPoint;
- }
- }
-
- // 用于
- public class SRStraightCurvatureLineMeasure : StraightCurvatureLine
- {
- private bool calflag = false;
- public SRStraightCurvatureLineMeasure(ItemMeta meta, IMeasureItem parent):base(meta, parent)
- {
-
- }
- protected override bool OnExecute(PointInfo args)
- {
- if (args.VisualArea is ISRDicom)
- {
- var dicomvisual = args.VisualArea as ISRDicom;
- bool isSRDen = dicomvisual.isSRDen();
- if (args.VisualArea.Mode == null || !isSRDen)
- {
- return false;
- }
- }
- else
- {
- var modewithurm = args.VisualArea.Mode as IModeWithURM;
- if (modewithurm == null||modewithurm?.URMStyle!="URM(Den)")
- return false;
- }
- calflag = false;
- var preState = State;
- var result = base.OnExecute(args);
- if (result && preState == ItemStates.Running && State == ItemStates.Finished)
- {
- calflag = true;
- }
- return result;
- }
- protected override void OnExecuted(PointInfo args)
- {
- if (GeoFeature != null && Calculator != null&& calflag)
- {
- Calculator.Calculate();
- }
- }
- internal static StraightCurvatureLine CreateSRStraightCurvatureLineMeasure(ItemMeta meta, IMeasureItem parent)
- {
- if (meta == null || meta.BaseType != MeasureTypes.SRStraightCurvatureLineMeasure)
- {
- throw new ArgumentException();
- }
- var item = new SRStraightCurvatureLineMeasure(meta, parent);
- item.Calculator = new SRStraightCurvatureLineCal(item);
- return item;
- }
- internal class SRStraightCurvatureLineCal : Calculator<StraightCurvatureLine>
- {
- internal static readonly string SRkey = "SRCurvature";
- protected internal override string[] SupportedOutputKeys
- {
- get { return new[] { SRkey }; }
- }
- public SRStraightCurvatureLineCal(StraightCurvatureLine straightLine)
- : base(straightLine)
- {
- }
- public SRStraightCurvatureLineCal()
- {
- }
- protected override void OnCalculate()
- {
- var wizardManager = ServiceManager.Instance.GetService<IWizardManager>();
- wizardManager.Startup("URM", "Calculating...", CalculatSRCurvature, double.NaN, WizardButtonEnum.None);
- }
- private void CalculatSRCurvature()
- {
- TaskManagerFactory.Instance.GetTaskManager("Calculating")
- .StartNewTaskProxy("CalculatSRCurvature", CalculteSRCurvature, OnSRCurvatureCalculated);
- }
- private void CalculteSRCurvature(TaskProxy proxy)
- {
- StraightLineFeature feature = RefItem.GeoFeature;
- int width = 0;
- int height = 0;
- double UrmPhysicalwidth = 0;
- double UrmPhysicalheight = 0;
- NativeArray srcArray = new NativeArray(0);
- if (feature != null && feature.HostArea is ISRDicom && feature.HostArea.Mode is IDicomMode)//dicom回放
- {
- var dicomvisual = feature.HostArea as ISRDicom;
- bool isSRDen = dicomvisual.isSRDen();
- if (!isSRDen)
- return;
- var dicomdate = dicomvisual.GetSRDicomFile(ref width, ref height, ref UrmPhysicalwidth,
- ref UrmPhysicalheight);
- //todo 坐标转换
- srcArray.Resize(dicomdate.Length);
- Marshal.Copy(dicomdate, 0, srcArray.Start, dicomdate.Length);
- }
- else if (feature.HostArea.Mode is IModeWithURM)//在URM runing时测量
- {
- var modewithURM = feature.HostArea.Mode as IModeWithURM;
- if(modewithURM.URMStyle!="URM(Den)")
- return;
- var date = modewithURM.UrmArray;
- width = modewithURM.URMImgWidth;
- height = modewithURM.URMImgHeight;
- UrmPhysicalwidth = modewithURM.URMPhyWidth;
- UrmPhysicalheight = modewithURM.URMPhyHeight;
- srcArray.Resize(date.Length);
- Marshal.Copy(date, 0, srcArray.Start, date.Length);
- }
- else
- {
- return;
- }
- if (srcArray.Length != 8 * width * height)
- {
- _delayAction.BeginInvoke();
- return;
- }
- double regionwidth = feature.HostArea.ViewPort.Region.Width;
- double regionheight = feature.HostArea.ViewPort.Region.Height;
- DPoint startDPoint = SRPointTrans.TransPointS2I(feature.StartPoint, regionwidth, regionheight,
- UrmPhysicalwidth, UrmPhysicalheight, width, height);
- DPoint endDPoint = SRPointTrans.TransPointS2I(feature.EndPoint, regionwidth, regionheight,
- UrmPhysicalwidth, UrmPhysicalheight, width, height);
- if (startDPoint.X < 0 || startDPoint.X > width || endDPoint.X < 0 || endDPoint.X > width
- || startDPoint.Y < 0 || startDPoint.Y > height || endDPoint.Y < 0 || endDPoint.Y > height)
- return;
- int outPointsNum = 0;
- double curvature = 0;
- var urmcal = feature.HostArea.Mode as IURMCal;
- if(urmcal == null)
- return;
- double[] outPoints = urmcal.GetSRCurvature(srcArray.Start, width, height, startDPoint.X,
- startDPoint.Y, endDPoint.X, endDPoint.Y, ref curvature, ref outPointsNum);
- DPoint[] points = new DPoint[outPointsNum];
- for (int i = 0; i < outPointsNum; i++)
- {
- DPoint imgpoint = new DPoint(outPoints[i], outPoints[i + outPointsNum]);
- points[i] = SRPointTrans.TransPointI2S(imgpoint, regionwidth, regionheight,
- UrmPhysicalwidth, UrmPhysicalheight, width, height);
- }
- List<GeometryFeature> autoLines = new List<GeometryFeature>
- {
- new ManualTraceFeature(points, feature.Creator, feature.XUnit, feature.YUnit)
- };
- ServiceManager.MainDispatcher.Invoke(UpdateChildFeatures, autoLines);
- feature.UpdateValue(PrimaryOutput, RoundValue(curvature, GetResultDigits(PrimaryOutput)), Unit.None);
- }
- public void UpdateChildFeatures(List<GeometryFeature> autoLines)
- {
- var feature = RefItem.GeoFeature;
- if (feature != null)
- feature.UpdateChildFeatures(autoLines);
- }
- private void OnSRCurvatureCalculated(TaskProxy proxy)
- {
- IWizardManager manager = ServiceManager.Instance.GetService<IWizardManager>();
- using (manager.ClosingWizard())
- {
- var showError = false;
- if (proxy.Task.IsCanceled)
- {
- Logger.WriteLineInfo("Task:{0} is canceled.", proxy.Name);
- }
- else if (proxy.Task.Exception != null)
- {
- showError = true;
- Logger.WriteLineError("Task:{0} failed, exception: {1}.", proxy.Name, proxy.Task.Exception);
- }
- if (!showError || (bool)proxy.Tag)
- {
- manager.Close();
- }
- else
- {
- manager.Close("SRCurvatureCalculate failed", false);
- }
- }
- }
- }
- }
- public class SRCurveCurvatureLineMeasure : Trace
- {
- private bool calflag = false;
- public SRCurveCurvatureLineMeasure(ItemMeta meta, IMeasureItem parent) : base(meta, parent)
- {
- }
- protected override bool OnExecute(PointInfo args)
- {
- var cal = Calculator as SRCurveCurvatureLineCal;
- if (args.VisualArea is ISRDicom)
- {
- var dicomvisual = args.VisualArea as ISRDicom;
- bool isSRDen = dicomvisual.isSRDen();
- if (args.VisualArea.Mode == null || !isSRDen)
- {
- return false;
- }
- }
- else
- {
- var modewithurm = args.VisualArea.Mode as IModeWithURM;
- if (modewithurm == null || modewithurm?.URMStyle != "URM(Den)")
- return false;
- }
- calflag = false;
- cal.calflag = false;
- var preState = State;
- var result = base.OnExecute(args);
- if (result && preState == ItemStates.Running && State == ItemStates.Finished)
- {
- calflag = true;
- cal.calflag = true;
- }
- return result;
- }
- protected override void OnExecuted(PointInfo args)
- {
- if (GeoFeature != null && Calculator != null && calflag)
- {
- Calculator.Calculate();
- }
- }
- internal static Trace CreateSRCurveCurvatureLineMeasure(ItemMeta meta, IMeasureItem parent)
- {
- if (meta == null || meta.BaseType != MeasureTypes.SRCurveCurvatureLineMeasure)
- {
- throw new ArgumentException();
- }
- var item = new SRCurveCurvatureLineMeasure(meta, parent);
- item.Calculator = new SRCurveCurvatureLineCal(item);
- return item;
- }
- internal class SRCurveCurvatureLineCal : Calculator<Trace>
- {
- public bool calflag = false;
- internal static readonly string URMkey = "SRCurvature";
- protected internal override string[] SupportedOutputKeys
- {
- get { return new[] { URMkey }; }
- }
- public SRCurveCurvatureLineCal(Trace trace)
- : base(trace)
- {
- }
- public SRCurveCurvatureLineCal()
- {
- }
- protected override void OnCalculate()
- {
- if (!calflag)
- return;
- PolyLineFeature feature = RefItem.GeoFeature;
- int width = 0;
- int height = 0;
- double UrmPhysicalwidth = 0;
- double UrmPhysicalheight = 0;
- NativeArray srcArray = new NativeArray(0);
- if (feature != null && feature.HostArea is ISRDicom && feature.HostArea.Mode is IDicomMode)//dicom回放
- {
- var dicomvisual = feature.HostArea as ISRDicom;
- bool isSRDen = dicomvisual.isSRDen();
- if (!isSRDen)
- return;
- var dicomdate = dicomvisual.GetSRDicomFile(ref width, ref height, ref UrmPhysicalwidth,
- ref UrmPhysicalheight);
- //todo 坐标转换
- srcArray.Resize(dicomdate.Length);
- Marshal.Copy(dicomdate, 0, srcArray.Start, dicomdate.Length);
- }
- else if (feature.HostArea.Mode is IModeWithURM)//在URM runing时测量
- {
- var modewithURM = feature.HostArea.Mode as IModeWithURM;
- if (modewithURM.URMStyle != "URM(Den)")
- return;
- var date = modewithURM.UrmArray;
- width = modewithURM.URMImgWidth;
- height = modewithURM.URMImgHeight;
- UrmPhysicalwidth = modewithURM.URMPhyWidth;
- UrmPhysicalheight = modewithURM.URMPhyHeight;
- srcArray.Resize(date.Length);
- Marshal.Copy(date, 0, srcArray.Start, date.Length);
- }
- else
- {
- return;
- }
- if (srcArray.Length != 8 * width * height)
- {
- _delayAction.BeginInvoke();
- return;
- }
- double regionwidth = feature.HostArea.ViewPort.Region.Width;
- double regionheight = feature.HostArea.ViewPort.Region.Height;
- var SrcDPoints =new List<DPoint>();
- for (int i = 0; i < feature.Points.Count; i++)
- {
- var curpoint = SRPointTrans.TransPointS2I(feature.Points[i], regionwidth, regionheight,
- UrmPhysicalwidth, UrmPhysicalheight, width, height);
- SrcDPoints.Add(curpoint);
- }
- if (SrcDPoints[0].X < 0 || SrcDPoints[0].X > width || SrcDPoints.Last().X < 0 || SrcDPoints.Last().X > width
- || SrcDPoints[0].Y < 0 || SrcDPoints[0].Y > height || SrcDPoints.Last().Y < 0 || SrcDPoints.Last().Y > height)
- return;
- double curvature = 0;
- var urmcal = feature.HostArea.Mode as IURMCal;
- if (urmcal == null)
- return;
- urmcal.GetSRTraceCurvaturel(srcArray.Start, width, height, SrcDPoints, ref curvature);
- feature.UpdateValue(PrimaryOutput, RoundValue(curvature, GetResultDigits(PrimaryOutput)), Unit.None);
- }
- }
- }
- public class SRCurvatureMeasure : MultiMethodItem
- {
- internal SRCurvatureMeasure(ItemMeta meta, IMeasureItem parent = null) : base(meta, parent)
- {
- }
- internal static SRCurvatureMeasure CreateSRCurvatureMeasure(ItemMeta meta, IMeasureItem parent)
- {
- if (meta.BaseType != MeasureTypes.SRCurvature)
- {
- throw new ArgumentException();
- }
- var item = new SRCurvatureMeasure(meta, parent);
- return item;
- }
- }
- public class URMVesselMeasure : StraightLine
- {
- private bool calflag = false;
- public URMVesselMeasure(ItemMeta meta, IMeasureItem parent) : base(meta, parent)
- {
- }
- protected override bool OnExecute(PointInfo args)
- {
- if (args.VisualArea is ISRDicom)
- {
- var dicomvisual = args.VisualArea as ISRDicom;
- bool isSRDen = dicomvisual.isSRDen();
- if (args.VisualArea.Mode == null || !isSRDen)
- {
- return false;
- }
- }
- else
- {
- var modewithurm = args.VisualArea.Mode as IModeWithURM;
- if (modewithurm == null || modewithurm?.URMStyle != "URM(Den)")
- return false;
- }
- calflag = false;
- var preState = State;
- var result = base.OnExecute(args);
- if (result && preState == ItemStates.Running && State == ItemStates.Finished)
- {
- calflag = true;
- }
- return result;
- }
- protected override void OnExecuted(PointInfo args)
- {
- if (GeoFeature != null && Calculator != null && calflag)
- {
- Calculator.Calculate();
- }
- }
- internal static URMVesselMeasure CreateURMVesselMeasure(ItemMeta meta, IMeasureItem parent)
- {
- if (meta == null || meta.BaseType != MeasureTypes.URMVesselMeasure)
- {
- throw new ArgumentException();
- }
- var item = new URMVesselMeasure(meta, parent);
- item.Calculator = new URMVesselMeasureCal(item);
- return item;
- }
- internal class URMVesselMeasureCal : Calculator<URMVesselMeasure>
- {
-
- public URMVesselMeasureCal(URMVesselMeasure straightLine)
- : base(straightLine)
- {
- }
- public URMVesselMeasureCal()
- {
- }
- protected internal override string[] SupportedOutputKeys
- {
- get
- {
- return new[]
- {
- MeasureTerms.MaxVessDistance, MeasureTerms.MinVessDistance, MeasureTerms.MeanVessDistacne,MeasureTerms.StdVessDistance,
- MeasureTerms.MaxVessDiameter, MeasureTerms.MinVessDiameter, MeasureTerms.MeanVessDiameter,MeasureTerms.StdVessDiameter
- };
- }
- }
- protected override void OnCalculate()
- {
- StraightLineFeature feature = RefItem.GeoFeature;
- int width = 0;
- int height = 0;
- double UrmPhysicalwidth = 0;
- double UrmPhysicalheight = 0;
- NativeArray srcArray = new NativeArray(0);
- if (feature != null && feature.HostArea is ISRDicom && feature.HostArea.Mode is IDicomMode)//dicom回放
- {
- var dicomvisual = feature.HostArea as ISRDicom;
- bool isSRDen = dicomvisual.isSRDen();
- if (!isSRDen)
- return;
- var dicomdate = dicomvisual.GetSRDicomFile(ref width, ref height, ref UrmPhysicalwidth,
- ref UrmPhysicalheight);
- //todo 坐标转换
- srcArray.Resize(dicomdate.Length);
- Marshal.Copy(dicomdate, 0, srcArray.Start, dicomdate.Length);
- }
- else if (feature.HostArea.Mode is IModeWithURM)//在URM runing时测量
- {
- var modewithURM = feature.HostArea.Mode as IModeWithURM;
- if (modewithURM.URMStyle != "URM(Den)")
- return;
- var date = modewithURM.UrmArray;
- width = modewithURM.URMImgWidth;
- height = modewithURM.URMImgHeight;
- UrmPhysicalwidth = modewithURM.URMPhyWidth;
- UrmPhysicalheight = modewithURM.URMPhyHeight;
- srcArray.Resize(date.Length);
- Marshal.Copy(date, 0, srcArray.Start, date.Length);
- }
- else
- {
- return;
- }
- if (srcArray.Length != 8 * width * height)
- {
- _delayAction.BeginInvoke();
- return;
- }
- double regionwidth = feature.HostArea.ViewPort.Region.Width;
- double regionheight = feature.HostArea.ViewPort.Region.Height;
- DPoint startDPoint = SRPointTrans.TransPointS2I(feature.StartPoint, regionwidth, regionheight,
- UrmPhysicalwidth, UrmPhysicalheight, width, height);
- DPoint endDPoint = SRPointTrans.TransPointS2I(feature.EndPoint, regionwidth, regionheight,
- UrmPhysicalwidth, UrmPhysicalheight, width, height);
- if (startDPoint.X < 0 || startDPoint.X > width || endDPoint.X < 0 || endDPoint.X > width
- || startDPoint.Y < 0 || startDPoint.Y > height || endDPoint.Y < 0 || endDPoint.Y > height)
- return;
- List<DPoint> Points=new List<DPoint>();
- Points.Add(startDPoint);
- Points.Add(endDPoint);
- var cmlength=Math.Sqrt(Math.Pow((feature.StartPoint.X- feature.EndPoint.X),2)+Math.Pow((feature.StartPoint.Y - feature.EndPoint.Y), 2));
- var pixelscaler = UrmPhysicalwidth / width;
- int outPointNum = (int)(cmlength*1000);
- SRMeasurePoint[] outPoints=new SRMeasurePoint[outPointNum];
- var urmcal = feature.HostArea.Mode as IURMCal;
- if (urmcal == null)
- return;
- var result = urmcal.GetUrmVessMeasureResult(srcArray.Start, width, height, Points, pixelscaler, outPoints);
- foreach (var outputItem in Outputs)
- {
- outputItem.UpdateDescription(outputItem.Name);
- if (string.Equals(outputItem.Name, MeasureTerms.MaxVessDistance))
- {
- feature.UpdateValue(outputItem, RoundValue(result.MaxVessDistance, outputItem), Unit.mm);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.MinVessDistance))
- {
- feature.UpdateValue(outputItem, RoundValue(result.MinVessDistance, outputItem), Unit.mm);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.MeanVessDistacne))
- {
- feature.UpdateValue(outputItem, RoundValue(result.MeanVessDistacne, outputItem), Unit.mm);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.StdVessDistance))
- {
- feature.UpdateValue(outputItem, RoundValue(Math.Sqrt(result.VarianceVessDistance), outputItem), Unit.mm);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.MaxVessDiameter))
- {
- feature.UpdateValue(outputItem, RoundValue(result.MaxVessDiameter, outputItem), Unit.mm);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.MinVessDiameter))
- {
- feature.UpdateValue(outputItem, RoundValue(result.MinVessDiameter, outputItem), Unit.mm);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.MeanVessDiameter))
- {
- feature.UpdateValue(outputItem, RoundValue(result.MeanVessDiameter, outputItem), Unit.mm);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.StdVessDiameter))
- {
- feature.UpdateValue(outputItem, RoundValue(Math.Sqrt(result.VarianceVessDiameter), outputItem), Unit.mm);
- }
- }
- var maxPointIndex = result.MaxPos;
- var minPointIndex = result.MinPos;
- var srChart = ServiceManager.Instance.GetService<IMeasureService>().SrChart;
- srChart.Update(feature, outPoints.Select(x => new DPoint(x.X, x.Y)).ToArray(), maxPointIndex, minPointIndex);
- }
- }
- }
- internal class SRROIMeasure : Rect
- {
- private bool calflag=false;
- public SRROIMeasure(ItemMeta meta, IMeasureItem parent = null)
- : base(meta, parent)
- {
- }
- internal static SRROIMeasure CreateSRROIMeasure(ItemMeta meta, IMeasureItem parent)
- {
- if (meta == null || meta.BaseType != MeasureTypes.SRRoiDensity )
- {
- throw new ArgumentException();
- }
- var SRROI = new SRROIMeasure(meta, parent);
- SRROI.Calculator = new SRROICal(SRROI);
- return SRROI;
- }
- public override void DownloadValueFromPreviousItem()
- {
- }
- protected override bool OnExecute(PointInfo args)
- {
- var cal = Calculator as SRROICal;
- if (args.VisualArea is ISRDicom)
- {
- var dicomvisual = args.VisualArea as ISRDicom;
- bool isSRDen = dicomvisual.isSRDen();
- if (args.VisualArea.Mode == null || !isSRDen)
- {
- return false;
- }
- }
- else
- {
- var modewithurm = args.VisualArea.Mode as IModeWithURM;
- if (modewithurm == null || modewithurm?.URMStyle != "URM(Den)")
- return false;
- }
- calflag = false;
- cal.calflag = false;
- var preState = State;
- var result = base.OnExecute(args);
- if (result && preState == ItemStates.Running && State == ItemStates.Finished)
- {
- calflag = true;
- cal.calflag = true;
- }
- return result;
- }
- protected override void OnExecuted(PointInfo args)
- {
- if (GeoFeature != null && Calculator != null && calflag)
- {
- Calculator.Calculate();
- }
- }
- internal sealed class SRROICal : Calculator<SRROIMeasure>
- {
- public bool calflag=false;
- public SRROICal(SRROIMeasure item)
- : base(item)
- {
- }
- public SRROICal()
- {
- }
- protected internal override string[] SupportedOutputKeys
- {
- get
- {
- return new[]
- {
- MeasureTerms.URMDenROI
- };
- }
- }
- protected override void OnCalculate()
- {
- if(!calflag)
- return;
- RectFeature feature = RefItem.GeoFeature;
- int width = 0;
- int height = 0;
- double UrmPhysicalwidth = 0;
- double UrmPhysicalheight = 0;
- NativeArray srcArray = new NativeArray(0);
- if (feature != null && feature.HostArea is ISRDicom && feature.HostArea.Mode is IDicomMode)//dicom回放
- {
- var dicomvisual = feature.HostArea as ISRDicom;
- bool isSRDen = dicomvisual.isSRDen();
- if (!isSRDen)
- return;
- var dicomdate = dicomvisual.GetSRDicomFile(ref width, ref height, ref UrmPhysicalwidth,
- ref UrmPhysicalheight);
- //todo 坐标转换
- srcArray.Resize(dicomdate.Length);
- Marshal.Copy(dicomdate, 0, srcArray.Start, dicomdate.Length);
- }
- else if (feature.HostArea.Mode is IModeWithURM)//在URM runing时测量
- {
- var modewithURM = feature.HostArea.Mode as IModeWithURM;
- if (modewithURM.URMStyle != "URM(Den)")
- return;
- var date = modewithURM.UrmArray;
- width = modewithURM.URMImgWidth;
- height = modewithURM.URMImgHeight;
- UrmPhysicalwidth = modewithURM.URMPhyWidth;
- UrmPhysicalheight = modewithURM.URMPhyHeight;
- srcArray.Resize(date.Length);
- Marshal.Copy(date, 0, srcArray.Start, date.Length);
- }
- else
- {
- return;
- }
- if (srcArray.Length != 8 * width * height)
- {
- _delayAction.BeginInvoke();
- return;
- }
- //todo 坐标转换
- double regionwidth = feature.HostArea.ViewPort.Region.Width;
- double regionheight = feature.HostArea.ViewPort.Region.Height;
- DPoint startDPoint = SRPointTrans.TransPointS2I(feature.TopLeft, regionwidth, regionheight,
- UrmPhysicalwidth, UrmPhysicalheight, width, height);
- DPoint endDPoint = SRPointTrans.TransPointS2I(feature.BottomRight, regionwidth, regionheight,
- UrmPhysicalwidth, UrmPhysicalheight, width, height);
- if (startDPoint.X < 0 || startDPoint.X > width || endDPoint.X < 0 || endDPoint.X > width
- || startDPoint.Y < 0 || startDPoint.Y > height || endDPoint.Y < 0 || endDPoint.Y > height)
- return;
- int outPointsNum = 0;
- var urmcal = feature.HostArea.Mode as IURMCal;
- if (urmcal == null)
- return;
- double roivel = urmcal.GetSRRoiVel(srcArray.Start, width, height, startDPoint.X,
- startDPoint.Y, endDPoint.X, endDPoint.Y);
- Outputs[0].UpdateDescription(Outputs[0].Name);
- feature.UpdateValue(Outputs[0], RoundValue(roivel * 100, GetResultDigits(PrimaryOutput)), Unit.percent);
- }
- }
- }
- internal class URMRectDenMeasure : Rect
- {
- private bool calflag = false;
- public URMRectDenMeasure(ItemMeta meta, IMeasureItem parent = null)
- : base(meta, parent)
- {
- }
- internal static URMRectDenMeasure CreateURMRectDenMeasure(ItemMeta meta, IMeasureItem parent)
- {
- if (meta == null || meta.BaseType != MeasureTypes.URMRectDenMeasure)
- {
- throw new ArgumentException();
- }
- var item = new URMRectDenMeasure(meta, parent);
- item.Calculator = new URMRectDenMeasureCal(item);
- return item;
- }
- public override void DownloadValueFromPreviousItem()
- {
- }
- protected override bool OnExecute(PointInfo args)
- {
- var cal = Calculator as URMRectDenMeasureCal;
- if (args.VisualArea is ISRDicom)
- {
- var dicomvisual = args.VisualArea as ISRDicom;
- bool isSRDen = dicomvisual.isSRDen();
- if (args.VisualArea.Mode == null || !isSRDen)
- {
- return false;
- }
- }
- else
- {
- var modewithurm = args.VisualArea.Mode as IModeWithURM;
- if (modewithurm == null || modewithurm?.URMStyle != "URM(Den)")
- return false;
- }
- calflag = false;
- cal.calflag = false;
- var preState = State;
- var result = base.OnExecute(args);
- if (result && preState == ItemStates.Running && State == ItemStates.Finished)
- {
- calflag = true;
- cal.calflag = true;
- }
- return result;
- }
- protected override void OnExecuted(PointInfo args)
- {
- if (GeoFeature != null && Calculator != null && calflag)
- {
- Calculator.Calculate();
- }
- }
- internal sealed class URMRectDenMeasureCal : Calculator<URMRectDenMeasure>
- {
- public bool calflag = false;
- public URMRectDenMeasureCal(URMRectDenMeasure item)
- : base(item)
- {
- }
- public URMRectDenMeasureCal()
- {
- }
- protected internal override string[] SupportedOutputKeys
- {
- get
- {
- return new[]
- {
- MeasureTerms.URMDenROI, MeasureTerms.URMDenFractalDim, MeasureTerms.URMDenMax,
- MeasureTerms.URMDenMin, MeasureTerms.URMDenMean, MeasureTerms.URMDenStd, MeasureTerms.Area,
- MeasureTerms.URMDenROIIn, MeasureTerms.URMDenFractalDimIn, MeasureTerms.URMDenMaxIn,
- MeasureTerms.URMDenMinIn, MeasureTerms.URMDenMeanIn, MeasureTerms.URMDenStdIn, MeasureTerms.URMAreaIn,
- MeasureTerms.URMDenROIOut, MeasureTerms.URMDenFractalDimOut, MeasureTerms.URMDenMaxOut,
- MeasureTerms.URMDenMinOut, MeasureTerms.URMDenMeanOut, MeasureTerms.URMDenStdOut, MeasureTerms.URMAreaOut,
- };
- }
- }
- protected override void OnCalculate()
- {
- if (!calflag)
- return;
- RectFeature feature = RefItem.GeoFeature;
- int width = 0;
- int height = 0;
- double UrmPhysicalwidth = 0;
- double UrmPhysicalheight = 0;
- NativeArray srcArray = new NativeArray(0);
- if (feature != null && feature.HostArea is ISRDicom && feature.HostArea.Mode is IDicomMode)//dicom回放
- {
- var dicomvisual = feature.HostArea as ISRDicom;
- bool isSRDen = dicomvisual.isSRDen();
- if (!isSRDen)
- return;
- var dicomdate = dicomvisual.GetSRDicomFile(ref width, ref height, ref UrmPhysicalwidth,
- ref UrmPhysicalheight);
- //todo 坐标转换
- srcArray.Resize(dicomdate.Length);
- Marshal.Copy(dicomdate, 0, srcArray.Start, dicomdate.Length);
- }
- else if (feature.HostArea.Mode is IModeWithURM)//在URM runing时测量
- {
- var modewithURM = feature.HostArea.Mode as IModeWithURM;
- if (modewithURM.URMStyle != "URM(Den)")
- return;
- var date = modewithURM.UrmArray;
- width = modewithURM.URMImgWidth;
- height = modewithURM.URMImgHeight;
- UrmPhysicalwidth = modewithURM.URMPhyWidth;
- UrmPhysicalheight = modewithURM.URMPhyHeight;
- srcArray.Resize(date.Length);
- Marshal.Copy(date, 0, srcArray.Start, date.Length);
- }
- else
- {
- return;
- }
- if (srcArray.Length != 8 * width * height)
- {
- _delayAction.BeginInvoke();
- return;
- }
- //todo 坐标转换
- double regionwidth = feature.HostArea.ViewPort.Region.Width;
- double regionheight = feature.HostArea.ViewPort.Region.Height;
- DPoint startDPoint = SRPointTrans.TransPointS2I(feature.TopLeft, regionwidth, regionheight,
- UrmPhysicalwidth, UrmPhysicalheight, width, height);
- DPoint endDPoint = SRPointTrans.TransPointS2I(feature.BottomRight, regionwidth, regionheight,
- UrmPhysicalwidth, UrmPhysicalheight, width, height);
-
- if (startDPoint.X < 0 || startDPoint.X > width || endDPoint.X < 0 || endDPoint.X > width
- || startDPoint.Y < 0 || startDPoint.Y > height || endDPoint.Y < 0 || endDPoint.Y > height)
- return;
- List<DPoint> ImagePoint = new List<DPoint>();
- double areaScaler = (UrmPhysicalwidth / width) * (UrmPhysicalheight / height);
- ImagePoint.Add(startDPoint);
- ImagePoint.Add(endDPoint);
- var urmcal = feature.HostArea.Mode as IURMCal;
- if (urmcal == null)
- return;
- var result = urmcal.GetURMDenMeasureResult(srcArray.Start, width, height, ImagePoint,areaScaler);
- foreach (var outputItem in Outputs)
- {
- outputItem.UpdateDescription(outputItem.Name);
- if (string.Equals(outputItem.Name,MeasureTerms.URMDenROI))
- {
- feature.UpdateValue(outputItem, RoundValue(result.RoiDen*100, outputItem), Unit.percent);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.URMDenFractalDim))
- {
- feature.UpdateValue(outputItem, RoundValue(result.RoiFractalDim, outputItem), Unit.None);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.URMDenMax))
- {
- feature.UpdateValue(outputItem, RoundValue(result.MaxDensity, outputItem), Unit.None);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.URMDenMin))
- {
- feature.UpdateValue(outputItem, RoundValue(result.MinDensity, outputItem), Unit.None);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.URMDenMean))
- {
- feature.UpdateValue(outputItem, RoundValue(result.MeanDensity, outputItem), Unit.None);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.URMDenStd))
- {
- feature.UpdateValue(outputItem, RoundValue(Math.Sqrt(result.VarianceDensity), outputItem), Unit.None);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.Area))
- {
- feature.UpdateValue(outputItem, RoundValue(result.RoiArea, outputItem), Unit.cm2);
- }
- }
- }
- }
- }
- internal class URMRectVelMeasure : Rect
- {
- private bool calflag = false;
- public URMRectVelMeasure(ItemMeta meta, IMeasureItem parent = null)
- : base(meta, parent)
- {
- }
- internal static URMRectVelMeasure CreateURMRectVelMeasure(ItemMeta meta, IMeasureItem parent)
- {
- if (meta == null || meta.BaseType != MeasureTypes.URMRectVelMeasure)
- {
- throw new ArgumentException();
- }
- var item = new URMRectVelMeasure(meta, parent);
- item.Calculator = new URMRectVelMeasureCal(item);
- return item;
- }
- public override void DownloadValueFromPreviousItem()
- {
- }
- protected override bool OnExecute(PointInfo args)
- {
- var cal = Calculator as URMRectVelMeasureCal;
- if (args.VisualArea is ISRDicom)
- {
- var dicomvisual = args.VisualArea as ISRDicom;
- bool isSrVel = dicomvisual.isSRVel();
- if (args.VisualArea.Mode == null || !isSrVel)
- {
- return false;
- }
- }
- else
- {
- var modewithurm = args.VisualArea.Mode as IModeWithURM;
- if (modewithurm == null || modewithurm?.URMStyle != "URM(Vel)")
- return false;
- }
- calflag = false;
- cal.calflag = false;
- var preState = State;
- var result = base.OnExecute(args);
- if (result && preState == ItemStates.Running && State == ItemStates.Finished)
- {
- calflag = true;
- cal.calflag = true;
- }
- return result;
- }
- protected override void OnExecuted(PointInfo args)
- {
- if (GeoFeature != null && Calculator != null && calflag)
- {
- Calculator.Calculate();
- }
- }
- internal sealed class URMRectVelMeasureCal : Calculator<URMRectVelMeasure>
- {
- public bool calflag = false;
- public URMRectVelMeasureCal(URMRectVelMeasure item)
- : base(item)
- {
- }
- public URMRectVelMeasureCal()
- {
- }
- protected internal override string[] SupportedOutputKeys
- {
- get
- {
- return new[]
- {
- MeasureTerms.URMVelMax, MeasureTerms.URMVelMin, MeasureTerms.URMVelMean, MeasureTerms.URMVelStd, MeasureTerms.Area,
- MeasureTerms.URMVelMaxIn, MeasureTerms.URMVelMinIn, MeasureTerms.URMVelMeanIn, MeasureTerms.URMVelStdIn, MeasureTerms.URMAreaIn,
- MeasureTerms.URMVelMaxOut, MeasureTerms.URMVelMinOut, MeasureTerms.URMVelMeanOut, MeasureTerms.URMVelStdOut, MeasureTerms.URMAreaOut,
- };
- }
- }
- protected override void OnCalculate()
- {
- if (!calflag)
- return;
- RectFeature feature = RefItem.GeoFeature;
- int width = 0;
- int height = 0;
- double UrmPhysicalwidth = 0;
- double UrmPhysicalheight = 0;
- double UrmMinVel = 0;
- NativeArray srcArray = new NativeArray(0);
- if (feature != null && feature.HostArea is ISRDicom && feature.HostArea.Mode is IDicomMode)//dicom回放
- {
- var dicomvisual = feature.HostArea as ISRDicom;
- bool isSRVel = dicomvisual.isSRVel();
- if (!isSRVel)
- return;
- var dicomdate = dicomvisual.GetSRDicomFile(ref width, ref height, ref UrmPhysicalwidth,
- ref UrmPhysicalheight);
- //todo 坐标转换
- srcArray.Resize(dicomdate.Length);
- Marshal.Copy(dicomdate, 0, srcArray.Start, dicomdate.Length);
- UrmMinVel = dicomvisual.GetSRMinVel();
- }
- else if (feature.HostArea.Mode is IModeWithURM)//在URM runing时测量
- {
- var modewithURM = feature.HostArea.Mode as IModeWithURM;
- if (modewithURM.URMStyle != "URM(Vel)")
- return;
- var date = modewithURM.UrmArray;
- width = modewithURM.URMImgWidth;
- height = modewithURM.URMImgHeight;
- UrmPhysicalwidth = modewithURM.URMPhyWidth;
- UrmPhysicalheight = modewithURM.URMPhyHeight;
- UrmMinVel = modewithURM.URMMinVel;
- srcArray.Resize(date.Length);
- Marshal.Copy(date, 0, srcArray.Start, date.Length);
- }
- else
- {
- return;
- }
- //todo 坐标转换
- double regionwidth = feature.HostArea.ViewPort.Region.Width;
- double regionheight = feature.HostArea.ViewPort.Region.Height;
- DPoint startDPoint = SRPointTrans.TransPointS2I(feature.TopLeft, regionwidth, regionheight,
- UrmPhysicalwidth, UrmPhysicalheight, width, height);
- DPoint endDPoint = SRPointTrans.TransPointS2I(feature.BottomRight, regionwidth, regionheight,
- UrmPhysicalwidth, UrmPhysicalheight, width, height);
- if (startDPoint.X < 0 || startDPoint.X > width || endDPoint.X < 0 || endDPoint.X > width
- || startDPoint.Y < 0 || startDPoint.Y > height || endDPoint.Y < 0 || endDPoint.Y > height)
- return;
- List<DPoint> ImagePoint = new List<DPoint>();
- double areaScaler = (UrmPhysicalwidth / width) * (UrmPhysicalheight / height);
- ImagePoint.Add(startDPoint);
- ImagePoint.Add(endDPoint);
- var urmcal = feature.HostArea.Mode as IURMCal;
- if (urmcal == null)
- return;
- var result = urmcal.GetURMVelMeasureResult(srcArray.Start, width, height, ImagePoint, areaScaler);
- foreach (var outputItem in Outputs)
- {
- outputItem.UpdateDescription(outputItem.Name);
- if (string.Equals(outputItem.Name, MeasureTerms.URMVelMax))
- {
- feature.UpdateValue(outputItem, RoundValue(result.MaxVel+UrmMinVel, outputItem), Unit.mms);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.URMVelMin))
- {
- feature.UpdateValue(outputItem, RoundValue(result.MinVel + UrmMinVel, outputItem), Unit.mms);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.URMVelMean))
- {
- feature.UpdateValue(outputItem, RoundValue(result.MeanVel + UrmMinVel, outputItem), Unit.mms);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.URMVelStd))
- {
- feature.UpdateValue(outputItem, RoundValue(Math.Sqrt(result.VarianceVel), outputItem), Unit.mms);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.Area))
- {
- feature.UpdateValue(outputItem, RoundValue(result.RoiArea, outputItem), Unit.cm2);
- }
- }
- }
- }
- }
- internal class URMTraceDenMeasure : Trace
- {
- private bool calflag = false;
- public URMTraceDenMeasure(ItemMeta meta, IMeasureItem parent = null)
- : base(meta, parent)
- {
- }
- internal static URMTraceDenMeasure CreateURMTraceDenMeasure(ItemMeta meta, IMeasureItem parent)
- {
- if (meta == null || meta.BaseType != MeasureTypes.URMTraceDenMeasure)
- {
- throw new ArgumentException();
- }
- meta.AddArgs(new MeasureParam(IsAutoSnapKey, "true", DefinitionPriorityEnum.Root));
- var item = new URMTraceDenMeasure(meta, parent);
- item.Calculator = new URMTraceDenMeasureCal(item);
- return item;
- }
- public override void DownloadValueFromPreviousItem()
- {
- }
- protected override bool OnExecute(PointInfo args)
- {
- var cal = Calculator as URMTraceDenMeasureCal;
- if (args.VisualArea is ISRDicom)
- {
- var dicomvisual = args.VisualArea as ISRDicom;
- bool isSRDen = dicomvisual.isSRDen();
- if (args.VisualArea.Mode == null || !isSRDen)
- {
- return false;
- }
- }
- else
- {
- var modewithurm = args.VisualArea.Mode as IModeWithURM;
- if (modewithurm == null || modewithurm?.URMStyle != "URM(Den)")
- return false;
- }
- calflag = false;
- cal.calflag = false;
- var preState = State;
- var result = base.OnExecute(args);
- if (result && preState == ItemStates.Running && State == ItemStates.Finished)
- {
- calflag = true;
- cal.calflag = true;
- }
- return result;
- }
- protected override void OnExecuted(PointInfo args)
- {
- if (GeoFeature != null && Calculator != null && calflag)
- {
- Calculator.Calculate();
- }
- }
- internal sealed class URMTraceDenMeasureCal : Calculator<URMTraceDenMeasure>
- {
- public bool calflag = false;
- public URMTraceDenMeasureCal(URMTraceDenMeasure item)
- : base(item)
- {
- }
- public URMTraceDenMeasureCal()
- {
- }
- protected internal override string[] SupportedOutputKeys
- {
- get
- {
- return new[]
- {
- MeasureTerms.URMDenROI, MeasureTerms.URMDenFractalDim, MeasureTerms.URMDenMax,
- MeasureTerms.URMDenMin, MeasureTerms.URMDenMean, MeasureTerms.URMDenStd,
- MeasureTerms.Area
- };
- }
- }
- protected override void OnCalculate()
- {
- if (!calflag)
- return;
- PolyLineFeature feature = RefItem.GeoFeature;
- int width = 0;
- int height = 0;
- double UrmPhysicalwidth = 0;
- double UrmPhysicalheight = 0;
- NativeArray srcArray = new NativeArray(0);
- if (feature != null && feature.HostArea is ISRDicom && feature.HostArea.Mode is IDicomMode)//dicom回放
- {
- var dicomvisual = feature.HostArea as ISRDicom;
- bool isSRDen = dicomvisual.isSRDen();
- if (!isSRDen)
- return;
- var dicomdate = dicomvisual.GetSRDicomFile(ref width, ref height, ref UrmPhysicalwidth,
- ref UrmPhysicalheight);
- //todo 坐标转换
- srcArray.Resize(dicomdate.Length);
- Marshal.Copy(dicomdate, 0, srcArray.Start, dicomdate.Length);
- }
- else if (feature.HostArea.Mode is IModeWithURM)//在URM runing时测量
- {
- var modewithURM = feature.HostArea.Mode as IModeWithURM;
- if (modewithURM.URMStyle != "URM(Den)")
- return;
- var date = modewithURM.UrmArray;
- width = modewithURM.URMImgWidth;
- height = modewithURM.URMImgHeight;
- UrmPhysicalwidth = modewithURM.URMPhyWidth;
- UrmPhysicalheight = modewithURM.URMPhyHeight;
- srcArray.Resize(date.Length);
- Marshal.Copy(date, 0, srcArray.Start, date.Length);
- }
- else
- {
- return;
- }
- if (srcArray.Length != 8 * width * height)
- {
- _delayAction.BeginInvoke();
- return;
- }
- //todo 坐标转换
- double regionwidth = feature.HostArea.ViewPort.Region.Width;
- double regionheight = feature.HostArea.ViewPort.Region.Height;
- var points = RefItem.GeoFeature.Points;
- List<DPoint> ImagePoint = new List<DPoint>();
- for (int i = 0; i < points.Count; i++)
- {
- var point = SRPointTrans.TransPointS2I(points[i], regionwidth, regionheight,
- UrmPhysicalwidth, UrmPhysicalheight, width, height);
- if (point.X < 0 || point.X > width || point.X < 0 || point.X > width)
- continue;
- ImagePoint.Add(point);
- }
- double areaScaler = (UrmPhysicalwidth / width) * (UrmPhysicalheight / height);
- var urmcal = feature.HostArea.Mode as IURMCal;
- if (urmcal == null)
- return;
- var result = urmcal.GetURMDenMeasureResult(srcArray.Start, width, height, ImagePoint, areaScaler);
- foreach (var outputItem in Outputs)
- {
- outputItem.UpdateDescription(outputItem.Name);
- if (string.Equals(outputItem.Name, MeasureTerms.URMDenROI))
- {
- feature.UpdateValue(outputItem, RoundValue(result.RoiDen*100, outputItem), Unit.percent);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.URMDenFractalDim))
- {
- feature.UpdateValue(outputItem, RoundValue(result.RoiFractalDim, outputItem), Unit.None);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.URMDenMax))
- {
- feature.UpdateValue(outputItem, RoundValue(result.MaxDensity, outputItem), Unit.None);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.URMDenMin))
- {
- feature.UpdateValue(outputItem, RoundValue(result.MinDensity, outputItem), Unit.None);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.URMDenMean))
- {
- feature.UpdateValue(outputItem, RoundValue(result.MeanDensity, outputItem), Unit.None);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.URMDenStd))
- {
- feature.UpdateValue(outputItem, RoundValue(Math.Sqrt(result.VarianceDensity), outputItem), Unit.None);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.Area))
- {
- feature.UpdateValue(outputItem, RoundValue(result.RoiArea, outputItem), Unit.cm2);
- }
- }
- }
- }
- }
- internal class URMTraceVelMeasure : Trace
- {
- private bool calflag = false;
- public URMTraceVelMeasure(ItemMeta meta, IMeasureItem parent = null)
- : base(meta, parent)
- {
- }
- internal static URMTraceVelMeasure CreateURMTraceVelMeasure(ItemMeta meta, IMeasureItem parent)
- {
- if (meta == null || meta.BaseType != MeasureTypes.URMTraceVelMeasure)
- {
- throw new ArgumentException();
- }
- meta.AddArgs(new MeasureParam(IsAutoSnapKey, "true", DefinitionPriorityEnum.Root));
- var item = new URMTraceVelMeasure(meta, parent);
- item.Calculator = new URMTraceVelMeasureCal(item);
- return item;
- }
- public override void DownloadValueFromPreviousItem()
- {
- }
- protected override bool OnExecute(PointInfo args)
- {
- var cal = Calculator as URMTraceVelMeasureCal;
- if (args.VisualArea is ISRDicom)
- {
- var dicomvisual = args.VisualArea as ISRDicom;
- bool isSrVel = dicomvisual.isSRVel();
- if (args.VisualArea.Mode == null || !isSrVel)
- {
- return false;
- }
- }
- else
- {
- var modewithurm = args.VisualArea.Mode as IModeWithURM;
- if (modewithurm == null || modewithurm?.URMStyle != "URM(Vel)")
- return false;
- }
- calflag = false;
- cal.calflag = false;
- var preState = State;
- var result = base.OnExecute(args);
- if (result && preState == ItemStates.Running && State == ItemStates.Finished)
- {
- calflag = true;
- cal.calflag = true;
- }
- return result;
- }
- protected override void OnExecuted(PointInfo args)
- {
- if (GeoFeature != null && Calculator != null && calflag)
- {
- Calculator.Calculate();
- }
- }
- internal sealed class URMTraceVelMeasureCal : Calculator<URMTraceVelMeasure>
- {
- public bool calflag = false;
- public URMTraceVelMeasureCal(URMTraceVelMeasure item)
- : base(item)
- {
- }
- public URMTraceVelMeasureCal()
- {
- }
- protected internal override string[] SupportedOutputKeys
- {
- get
- {
- return new[]
- {
- MeasureTerms.URMVelMax, MeasureTerms.URMVelMin, MeasureTerms.URMVelMean, MeasureTerms.URMVelStd,
- MeasureTerms.Area
- };
- }
- }
- protected override void OnCalculate()
- {
- if (!calflag)
- return;
- PolyLineFeature feature = RefItem.GeoFeature;
- int width = 0;
- int height = 0;
- double UrmPhysicalwidth = 0;
- double UrmPhysicalheight = 0;
- double UrmMinVel = 0;
- NativeArray srcArray = new NativeArray(0);
- if (feature != null && feature.HostArea is ISRDicom && feature.HostArea.Mode is IDicomMode)//dicom回放
- {
- var dicomvisual = feature.HostArea as ISRDicom;
- bool isSRVel = dicomvisual.isSRVel();
- if (!isSRVel)
- return;
- var dicomdate = dicomvisual.GetSRDicomFile(ref width, ref height, ref UrmPhysicalwidth,
- ref UrmPhysicalheight);
- //todo 坐标转换
- srcArray.Resize(dicomdate.Length);
- Marshal.Copy(dicomdate, 0, srcArray.Start, dicomdate.Length);
- UrmMinVel = dicomvisual.GetSRMinVel();
- }
- else if (feature.HostArea.Mode is IModeWithURM)//在URM runing时测量
- {
- var modewithURM = feature.HostArea.Mode as IModeWithURM;
- if (modewithURM.URMStyle != "URM(Vel)")
- return;
- var date = modewithURM.UrmArray;
- width = modewithURM.URMImgWidth;
- height = modewithURM.URMImgHeight;
- UrmPhysicalwidth = modewithURM.URMPhyWidth;
- UrmPhysicalheight = modewithURM.URMPhyHeight;
- UrmMinVel = modewithURM.URMMinVel;
- srcArray.Resize(date.Length);
- Marshal.Copy(date, 0, srcArray.Start, date.Length);
- }
- else
- {
- return;
- }
- //todo 坐标转换
- double regionwidth = feature.HostArea.ViewPort.Region.Width;
- double regionheight = feature.HostArea.ViewPort.Region.Height;
- var points = RefItem.GeoFeature.Points;
- List<DPoint> ImagePoint = new List<DPoint>();
- for (int i = 0; i < points.Count; i++)
- {
- var point = SRPointTrans.TransPointS2I(points[i], regionwidth, regionheight,
- UrmPhysicalwidth, UrmPhysicalheight, width, height);
- if (point.X < 0 || point.X > width || point.X < 0 || point.X > width)
- continue;
- ImagePoint.Add(point);
- }
- double areaScaler = (UrmPhysicalwidth / width) * (UrmPhysicalheight / height);
- var urmcal = feature.HostArea.Mode as IURMCal;
- if (urmcal == null)
- return;
- var result = urmcal.GetURMVelMeasureResult(srcArray.Start, width, height, ImagePoint, areaScaler);
- foreach (var outputItem in Outputs)
- {
- outputItem.UpdateDescription(outputItem.Name);
- if (string.Equals(outputItem.Name, MeasureTerms.URMVelMax))
- {
- feature.UpdateValue(outputItem, RoundValue(result.MaxVel + UrmMinVel, outputItem), Unit.mms);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.URMVelMin))
- {
- feature.UpdateValue(outputItem, RoundValue(result.MinVel + UrmMinVel, outputItem), Unit.mms);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.URMVelMean))
- {
- feature.UpdateValue(outputItem, RoundValue(result.MeanVel + UrmMinVel, outputItem), Unit.mms);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.URMVelStd))
- {
- feature.UpdateValue(outputItem, RoundValue(Math.Sqrt(result.VarianceVel), outputItem), Unit.mms);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.Area))
- {
- feature.UpdateValue(outputItem, RoundValue(result.RoiArea, outputItem), Unit.cm2);
- }
- }
- }
- }
- }
- public class URMShellMeasure : Trace
- {
- private bool _isSmartMove;
- public FloatParameter ShellWidth { get; set; }
- internal static readonly string ShellWidthKey = "ShellWidth";
- internal static readonly string ShellWidthMetaKey = "ShellWidth_Meta";
- public static string ShellWidthMeta = "[1 2 3 4 5]";
- public static string ShellWidthDefaultValue = "1";
- public URMShellMeasure(ItemMeta meta, IMeasureItem parent = null)
- : base(meta, parent)
- {
- if (!meta.TryGetArgValue(ShellWidthMetaKey, out var shellWidthMeta) || string.IsNullOrEmpty(shellWidthMeta))
- {
- shellWidthMeta = ShellWidthMeta;
- }
- if (!meta.TryGetArgValue(ShellWidthKey, out var shellWidthDefaultValue) || string.IsNullOrEmpty(shellWidthDefaultValue))
- {
- shellWidthDefaultValue = ShellWidthDefaultValue;
- }
- ShellWidth = CreateArrayFloatParam(ShellWidthKey, shellWidthMeta, shellWidthDefaultValue);
- ShellWidth.ValueChanged += OnShellWidthParamsChanged;
- }
- protected override bool OnExecuteMouse(PointInfo args)
- {
- if (args != null && (State == ItemStates.Waiting || State == ItemStates.Running || State == ItemStates.Finished))
- {
- bool completed = false;
- if (State == ItemStates.Finished)
- {
- switch (args.Action)
- {
- case PointAction.MouseMove:
- case PointAction.MouseUp:
- return false;
- case PointAction.MouseDown:
- HandleMouseDownWhileFinished();
- break;
- }
- }
- if (State == ItemStates.Waiting)
- {
- switch (args.Action)
- {
- case PointAction.MouseMove:
- case PointAction.MouseUp:
- return false;
- case PointAction.MouseDown:
- HandleMouseDownWhileWaiting((MultiRegionPointInfo)args,
- (vertices, refItem, xUnit, yUnit) => new ShellTraceFeature(vertices, refItem, xUnit, yUnit));
- FirstPoint = args;
- if (!args.PixelPerX.AlmostEquals(0))
- {
- float pixelThreshold = PixelThreshold.AlmostEquals(0) ? 4 : PixelThreshold;
- Threshold = (float)(pixelThreshold / args.PixelPerX);
- }
- break;
- }
- }
- else if (State == ItemStates.Running)
- {
- var points = (MultiRegionPointInfo)args;
- if (!GeoFeature.AnyExist(points.AllAreas))
- {
- return false;
- }
- switch (args.Action)
- {
- case PointAction.MouseDown:
- IsClosed = true;
- GeoFeature.IsClosed = true;
- completed = true;
- break;
- case PointAction.MouseMove:
- //Use the IsAutoSnap to check if the trace need to use smart move.
- var measureService = ServiceManager.Instance.GetService<IMeasureService>();
- double autoSnapThreshold = measureService.Settings.AutoSnapThreshold;
- if (IsAutoSnap && autoSnapThreshold > 0)
- {
- //Change autosnapdistance unit from cm to pixel
- if (FirstPoint != null)
- {
- var current = points.AllRegionPoints.FirstOrDefault(x => x.VisualArea == FirstPoint.VisualArea);
- if (current != null)
- {
- var length = (FirstPoint.PhyPoint - current.PhyPoint).Length;
- if (GeoFeature.Points.Count < 3)
- {
- _isSmartMove = false;
- }
- if (length > autoSnapThreshold * 2.0 && !_isSmartMove)
- {
- _isSmartMove = true;
- }
- // User clear points if GeoFeature.ActivePoint== current.LogicPoint, so the trace shouldn't be smart closed.
- if (length < autoSnapThreshold && _isSmartMove && !GeoFeature.ActivePoint.AlmostEquals(current.LogicPoint))
- {
- IsClosed = true;
- GeoFeature.IsClosed = true;
- _isSmartMove = false;
- completed = true;
- GeoFeature.SyncStates(x =>
- {
- x.AddPoint(x.Points[0]);
- });
- GeoFeature.Points[0].SynchToMainMonitorScreen(GeoFeature.HostArea);
- break;
- }
- }
- }
- }
- foreach (var point in points.AllRegionPoints)
- {
- var geoFeature = GeoFeature.GetSpecificFeature(point.VisualArea);
- if (geoFeature != null)
- {
- geoFeature.AddPoint(point.LogicPoint);
- geoFeature.ActivePoint = point.LogicPoint;
- }
- }
- break;
- }
- }
- if (GeoFeature != null)
- {
- Calculator.Calculate();
- }
- //Update state
- if (args.Action == PointAction.MouseDown)
- {
- if (State == ItemStates.Waiting || State == ItemStates.Finished)
- {
- State = ItemStates.Running;
- }
- if (State == ItemStates.Running && completed)
- {
- FinishEditing((MultiRegionPointInfo)args);
- }
- }
- if ((args.Action == PointAction.MouseMove || args.Action == PointAction.TouchMove) && IsClosed)
- {
- if (State == ItemStates.Running && completed)
- {
- FinishEditing((MultiRegionPointInfo)args);
- }
- }
- return true;
- }
- return false;
- }
- protected override bool OnExecuteTouch(PointInfo args)
- {
- if (State == ItemStates.Finished)
- {
- switch (args.Action)
- {
- case PointAction.TouchUp:
- case PointAction.TouchMove:
- return false;
- case PointAction.TouchDown:
- HandleMouseDownWhileFinished();
- break;
- }
- }
- if (State == ItemStates.Waiting)
- {
- switch (args.Action)
- {
- case PointAction.TouchUp:
- case PointAction.TouchMove:
- return false;
- case PointAction.TouchDown:
- CaliperExtension.HideCaliper();
- HandleMouseDownWhileWaiting((MultiRegionPointInfo)args, (vertices, refItem, xUnit, yUnit) => new ShellTraceFeature(vertices, refItem, xUnit, yUnit));
- if (!args.PixelPerX.AlmostEquals(0))
- {
- float pixelThreshold = PixelThreshold.AlmostEquals(0) ? 4 : PixelThreshold;
- Threshold = (float)(pixelThreshold / args.PixelPerX);
- }
- IsNewMeasure = true;
- IsCompleted = false;
- StartSyncIgnore();
- State = ItemStates.Running;
- break;
- }
- }
- else if (State == ItemStates.Running)
- {
- var points = (MultiRegionPointInfo)args;
- switch (args.Action)
- {
- case PointAction.TouchUp:
- IsRelocatePoints = false;
- if (!IsIgnore)
- {
- if (!GeoFeature.ReEditing && !IsCompleted)
- {
- if (!GeoFeature.Points[0].AlmostEquals(GeoFeature.Points[GeoFeature.Points.Count / 2]))
- {
- IsCompleted = true;
- }
- }
- }
- IsNewMeasure = false;
- FinishEditingForTouch(points);
- GeoFeature.ReEditing = false;
- break;
- case PointAction.TouchMove:
- if (!IsIgnore)
- {
- if (IsNewMeasure && IsRelocatePoints)
- {
- RelocatePoints(points);
- }
- else
- {
- CaliperExtension.HideCaliper();
- if (!GeoFeature.ReEditing)
- {
- var measureService = ServiceManager.Instance.GetService<IMeasureService>();
- double autoSnapThreshold = measureService.Settings.AutoSnapThreshold;
- if ((IsAutoSnap) && autoSnapThreshold > 0)
- {
- var current = points.AllRegionPoints.FirstOrDefault(x => x.VisualArea == GeoFeature.HostArea);
- if (current != null)
- {
- var length = (GeoFeature.Points[0].PointToMainMonitorScreen(GeoFeature.HostArea) - (current.LogicPoint + ActiveTouchPointVector).PointToMainMonitorScreen(GeoFeature.HostArea)).Length;
- if (GeoFeature.Points.Count < 3)
- {
- IsSmartMove = false;
- }
- if (length > autoSnapThreshold * 2.0 && !IsSmartMove)
- {
- IsSmartMove = true;
- }
- if (length < autoSnapThreshold && IsSmartMove)
- {
- IsCompleted = true;
- IsSmartMove = false;
- GeoFeature.SyncStates(x =>
- {
- x.AddPoint(x.Points[0]);
- });
- FinishEditingForTouch(points);
- return true;
- }
- }
- }
- }
- foreach (var point in points.AllRegionPoints)
- {
- var geoFeature = GeoFeature.GetSpecificFeature(point.VisualArea);
- if (geoFeature != null)
- {
- var tempEndPoint = point.LogicPoint + ActiveTouchPointVector;
- if (!ServiceManager.Instance.GetService<ISystemSettingValues>().GetParameterValue("EnableCrossRegionOperation", false) &&
- !point.ContainerBound.Contains(tempEndPoint))
- {
- return true;
- }
- geoFeature.AddPoint(tempEndPoint);
- geoFeature.ActivePoint = tempEndPoint;
- }
- }
- }
- }
- break;
- case PointAction.TouchEnter:
- case PointAction.TouchDown:
- case PointAction.HoldGesture:
- base.OnExecuteTouch(args);
- break;
- }
- }
- return true;
- }
- internal override MeasuredFeature CreateMeasureFeatureFrom(MeasuredFeature source)
- {
- if (source is ShellTraceFeature feature)
- {
- return new ShellTraceFeature(feature.Points, this, feature.XUnit, feature.YUnit)
- {
- HostArea = feature.HostArea,
- ReferenceArea = feature.ReferenceArea,
- FrameIndex = feature.FrameIndex,
- VisualAreaType = feature.VisualAreaType,
- IsClosed = feature.IsClosed,
- ActivePointIndex = -1,
- };
- }
- return null;
- }
- private void OnShellWidthParamsChanged(object sender, EventArgs e)
- {
- Calculator.Calculate();
- }
- }
- public class URMShellDenMeasure : URMShellMeasure
- {
- public URMShellDenMeasure(ItemMeta meta, IMeasureItem parent = null)
- : base(meta, parent)
- {
- }
- internal static URMShellDenMeasure CreateURMShellDenMeasure(ItemMeta meta, IMeasureItem parent)
- {
- if (meta.BaseType != MeasureTypes.URMShellDenMeasure)
- {
- throw new ArgumentException();
- }
- meta.AddArgs(new MeasureParam(IsAutoSnapKey, "true", DefinitionPriorityEnum.Root));
- var item = new URMShellDenMeasure(meta, parent);
- item.Calculator = new URMShellDenMeasureCal(item);
- return item;
- }
- internal sealed class URMShellDenMeasureCal : Calculator<URMShellDenMeasure>
- {
- public URMShellDenMeasureCal(URMShellDenMeasure item)
- : base(item)
- {
- }
- public URMShellDenMeasureCal()
- {
- }
- protected internal override string[] SupportedOutputKeys
- {
- get
- {
- return new[]
- {
- MeasureTerms.URMDenROI, MeasureTerms.URMDenFractalDim, MeasureTerms.URMDenMax,
- MeasureTerms.URMDenMin, MeasureTerms.URMDenMean, MeasureTerms.URMDenStd, MeasureTerms.Area,
- MeasureTerms.URMDenROIIn, MeasureTerms.URMDenFractalDimIn, MeasureTerms.URMDenMaxIn,
- MeasureTerms.URMDenMinIn, MeasureTerms.URMDenMeanIn, MeasureTerms.URMDenStdIn, MeasureTerms.URMAreaIn,
- MeasureTerms.URMDenROIOut, MeasureTerms.URMDenFractalDimOut, MeasureTerms.URMDenMaxOut,
- MeasureTerms.URMDenMinOut, MeasureTerms.URMDenMeanOut, MeasureTerms.URMDenStdOut, MeasureTerms.URMAreaOut,
- };
- }
- }
- protected override void OnCalculate()
- {
- if (RefItem.State != ItemStates.Finished)
- return;
- PolyLineFeature feature = RefItem.GeoFeature;
- int width = 0;
- int height = 0;
- double UrmPhysicalwidth = 0;
- double UrmPhysicalheight = 0;
- NativeArray srcArray = new NativeArray(0);
- if (feature != null && feature.HostArea is ISRDicom && feature.HostArea.Mode is IDicomMode)//dicom回放
- {
- var dicomvisual = feature.HostArea as ISRDicom;
- bool isSRDen = dicomvisual.isSRDen();
- if (!isSRDen)
- return;
- var dicomdate = dicomvisual.GetSRDicomFile(ref width, ref height, ref UrmPhysicalwidth,
- ref UrmPhysicalheight);
- //todo 坐标转换
- srcArray.Resize(dicomdate.Length);
- Marshal.Copy(dicomdate, 0, srcArray.Start, dicomdate.Length);
- }
- else if (feature.HostArea.Mode is IModeWithURM)//在URM runing时测量
- {
- var modewithURM = feature.HostArea.Mode as IModeWithURM;
- if (modewithURM.URMStyle != "URM(Den)")
- return;
- var date = modewithURM.UrmArray;
- width = modewithURM.URMImgWidth;
- height = modewithURM.URMImgHeight;
- UrmPhysicalwidth = modewithURM.URMPhyWidth;
- UrmPhysicalheight = modewithURM.URMPhyHeight;
- srcArray.Resize(date.Length);
- Marshal.Copy(date, 0, srcArray.Start, date.Length);
- }
- else
- {
- return;
- }
- if (srcArray.Length != 8 * width * height)
- {
- _delayAction.BeginInvoke();
- return;
- }
- //todo 坐标转换
- double regionwidth = feature.HostArea.ViewPort.Region.Width;
- double regionheight = feature.HostArea.ViewPort.Region.Height;
- var points = RefItem.GeoFeature.Points;
- List<DPoint> ImagePoint = new List<DPoint>();
- for (int i = 0; i < points.Count; i++)
- {
- var point = SRPointTrans.TransPointS2I(points[i], regionwidth, regionheight,
- UrmPhysicalwidth, UrmPhysicalheight, width, height,false);
- if (point.X < 0 || point.X > width || point.X < 0 || point.X > width)
- continue;
- ImagePoint.Add(point);
- }
- if(ImagePoint.Count<3)
- return;
- double pixelscaler = UrmPhysicalwidth / width;
- var urmcal = feature.HostArea.Mode as IURMCal;
- if (urmcal == null)
- return;
- //double ShellWidth = 10;//Todo 这一块需要修改为根据设置的shellwidth来
- var result = urmcal.GetURMShellDenMeasureResult(srcArray.Start, width, height, ImagePoint, RefItem.ShellWidth.Value/10,
- pixelscaler, out var outshellPoints); //Todo OutShellPoint调用TransPointI2S转换为逻辑坐标用于绘制
- var transpoints = new List<DPoint>();
- foreach (var point in outshellPoints)
- {
- var transpoint = SRPointTrans.TransPointI2S(point, regionwidth, regionheight,
- UrmPhysicalwidth, UrmPhysicalheight, width, height);
- transpoints.Add(transpoint);
- }
- UpdateGeometry(transpoints);
- foreach (var outputItem in Outputs)
- {
- outputItem.UpdateDescription(outputItem.Name);
- if (string.Equals(outputItem.Name, MeasureTerms.URMDenROI))
- {
- feature.UpdateValue(outputItem, RoundValue(result.RoiDen * 100, outputItem), Unit.percent);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.URMDenFractalDim))
- {
- feature.UpdateValue(outputItem, RoundValue(result.RoiFractalDim, outputItem), Unit.None);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.URMDenMax))
- {
- feature.UpdateValue(outputItem, RoundValue(result.MaxDensity, outputItem), Unit.None);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.URMDenMin))
- {
- feature.UpdateValue(outputItem, RoundValue(result.MinDensity, outputItem), Unit.None);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.URMDenMean))
- {
- feature.UpdateValue(outputItem, RoundValue(result.MeanDensity, outputItem), Unit.None);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.URMDenStd))
- {
- feature.UpdateValue(outputItem, RoundValue(Math.Sqrt(result.VarianceDensity), outputItem), Unit.None);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.Area))
- {
- feature.UpdateValue(outputItem, RoundValue(result.RoiArea, outputItem), Unit.cm2);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.URMDenROIIn))
- {
- feature.UpdateValue(outputItem, RoundValue(result.InRoiDen * 100, outputItem), Unit.percent);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.URMDenFractalDimIn))
- {
- feature.UpdateValue(outputItem, RoundValue(result.InRoiFractalDim, outputItem), Unit.None);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.URMDenMaxIn))
- {
- feature.UpdateValue(outputItem, RoundValue(result.InMaxDensity, outputItem), Unit.None);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.URMDenMinIn))
- {
- feature.UpdateValue(outputItem, RoundValue(result.InMinDensity, outputItem), Unit.None);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.URMDenMeanIn))
- {
- feature.UpdateValue(outputItem, RoundValue(result.InMeanDensity, outputItem), Unit.None);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.URMDenStdIn))
- {
- feature.UpdateValue(outputItem, RoundValue(Math.Sqrt(result.InVarianceDensity), outputItem), Unit.None);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.URMAreaIn))
- {
- feature.UpdateValue(outputItem, RoundValue(result.InRoiArea, outputItem), Unit.cm2);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.URMDenROIOut))
- {
- feature.UpdateValue(outputItem, RoundValue(result.OutRoiDen * 100, outputItem), Unit.percent);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.URMDenFractalDimOut))
- {
- feature.UpdateValue(outputItem, RoundValue(result.OutRoiFractalDim, outputItem), Unit.None);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.URMDenMaxOut))
- {
- feature.UpdateValue(outputItem, RoundValue(result.OutMaxDensity, outputItem), Unit.None);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.URMDenMinOut))
- {
- feature.UpdateValue(outputItem, RoundValue(result.OutMinDensity, outputItem), Unit.None);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.URMDenMeanOut))
- {
- feature.UpdateValue(outputItem, RoundValue(result.OutMeanDensity, outputItem), Unit.None);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.URMDenStdOut))
- {
- feature.UpdateValue(outputItem, RoundValue(Math.Sqrt(result.OutVarianceDensity), outputItem), Unit.None);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.URMAreaOut))
- {
- feature.UpdateValue(outputItem, RoundValue(result.OutRoiArea, outputItem), Unit.cm2);
- }
- }
- }
- protected void UpdateGeometry(List<DPoint> outResult)
- {
- var geometry = new TraceLineFeature(outResult, RefItem, RefItem.GeoFeature.XUnit,
- RefItem.GeoFeature.YUnit, false)
- {
- IsClosed = true,
- };
- if (RefItem.GeoFeature is ShellTraceFeature feature)
- {
- feature.UpdateChildFeatures(new List<GeometryFeature> { geometry });
- }
- }
- }
- }
- public class URMShellFractalDim: URMShellMeasure
- {
- public URMShellFractalDim(ItemMeta meta, IMeasureItem parent = null)
- : base(meta, parent)
- {
- }
- internal static URMShellFractalDim CreateURMShellFractalDim(ItemMeta meta, IMeasureItem parent)
- {
- if (meta.BaseType != MeasureTypes.URMShellFractalDim)
- {
- throw new ArgumentException();
- }
- meta.AddArgs(new MeasureParam(IsAutoSnapKey, "true", DefinitionPriorityEnum.Root));
- var item = new URMShellFractalDim(meta, parent);
- item.Calculator = new URMShellFractalDimCal(item);
- return item;
- }
- internal sealed class URMShellFractalDimCal : Calculator<URMShellFractalDim>
- {
- public URMShellFractalDimCal(URMShellFractalDim item)
- : base(item)
- {
- }
- public URMShellFractalDimCal()
- {
- }
- protected internal override string[] SupportedOutputKeys
- {
- get
- {
- return new[]
- {
- MeasureTerms.URMDenFractalDim,
- };
- }
- }
- protected override void OnCalculate()
- {
- if (RefItem.State != ItemStates.Finished)
- return;
- PolyLineFeature feature = RefItem.GeoFeature;
- int width = 0;
- int height = 0;
- double UrmPhysicalwidth = 0;
- double UrmPhysicalheight = 0;
- NativeArray srcArray = new NativeArray(0);
- if (feature != null && feature.HostArea is ISRDicom && feature.HostArea.Mode is IDicomMode)//dicom回放
- {
- var dicomvisual = feature.HostArea as ISRDicom;
- bool isSRDen = dicomvisual.isSRDen();
- if (!isSRDen)
- return;
- var dicomdate = dicomvisual.GetSRDicomFile(ref width, ref height, ref UrmPhysicalwidth,
- ref UrmPhysicalheight);
- //todo 坐标转换
- srcArray.Resize(dicomdate.Length);
- Marshal.Copy(dicomdate, 0, srcArray.Start, dicomdate.Length);
- }
- else if (feature.HostArea.Mode is IModeWithURM)//在URM runing时测量
- {
- var modewithURM = feature.HostArea.Mode as IModeWithURM;
- if (modewithURM.URMStyle != "URM(Den)")
- return;
- var date = modewithURM.UrmArray;
- width = modewithURM.URMImgWidth;
- height = modewithURM.URMImgHeight;
- UrmPhysicalwidth = modewithURM.URMPhyWidth;
- UrmPhysicalheight = modewithURM.URMPhyHeight;
- srcArray.Resize(date.Length);
- Marshal.Copy(date, 0, srcArray.Start, date.Length);
- }
- else
- {
- return;
- }
- if (srcArray.Length != 8 * width * height)
- {
- _delayAction.BeginInvoke();
- return;
- }
- //todo 坐标转换
- double regionwidth = feature.HostArea.ViewPort.Region.Width;
- double regionheight = feature.HostArea.ViewPort.Region.Height;
- var points = RefItem.GeoFeature.Points;
- List<DPoint> ImagePoint = new List<DPoint>();
- for (int i = 0; i < points.Count; i++)
- {
- var point = SRPointTrans.TransPointS2I(points[i], regionwidth, regionheight,
- UrmPhysicalwidth, UrmPhysicalheight, width, height,false);
- if (point.X < 0 || point.X > width || point.X < 0 || point.X > width)
- continue;
- ImagePoint.Add(point);
- }
- if (ImagePoint.Count < 3)
- return;
- double pixelscaler = UrmPhysicalwidth / width;
- var urmcal = feature.HostArea.Mode as IURMCal;
- if (urmcal == null)
- return;
- var result = urmcal.GetURMShellDenMeasureResult(srcArray.Start, width, height, ImagePoint, RefItem.ShellWidth.Value / 10,
- pixelscaler, out var outshellPoints); //Todo OutShellPoint调用TransPointI2S转换为逻辑坐标用于绘制
- var transpoints = new List<DPoint>();
- foreach (var point in outshellPoints)
- {
- var transpoint = SRPointTrans.TransPointI2S(point, regionwidth, regionheight,
- UrmPhysicalwidth, UrmPhysicalheight, width, height);
- transpoints.Add(transpoint);
- }
- UpdateGeometry(transpoints);
- Outputs[0].UpdateDescription(Outputs[0].Name);
- feature.UpdateValue(Outputs[0], RoundValue(result.RoiFractalDim, GetResultDigits(PrimaryOutput)), Unit.None);
- }
- protected void UpdateGeometry(List<DPoint> outResult)
- {
- var geometry = new TraceLineFeature(outResult, RefItem, RefItem.GeoFeature.XUnit,
- RefItem.GeoFeature.YUnit, false)
- {
- IsClosed = true,
- };
- if (RefItem.GeoFeature is ShellTraceFeature feature)
- {
- feature.UpdateChildFeatures(new List<GeometryFeature> { geometry });
- }
- }
- }
- }
- public class URMShellDensity : URMShellMeasure
- {
- public URMShellDensity(ItemMeta meta, IMeasureItem parent = null)
- : base(meta, parent)
- {
- }
- internal static URMShellDensity CreateURMShellDensity(ItemMeta meta, IMeasureItem parent)
- {
- if (meta.BaseType != MeasureTypes.URMShellDensity)
- {
- throw new ArgumentException();
- }
- meta.AddArgs(new MeasureParam(IsAutoSnapKey, "true", DefinitionPriorityEnum.Root));
- var item = new URMShellDensity(meta, parent);
- item.Calculator = new URMShellDensityCal(item);
- return item;
- }
- internal sealed class URMShellDensityCal : Calculator<URMShellDensity>
- {
- public URMShellDensityCal(URMShellDensity item)
- : base(item)
- {
- }
- public URMShellDensityCal()
- {
- }
- protected internal override string[] SupportedOutputKeys
- {
- get
- {
- return new[]
- {
- MeasureTerms.URMDenROI,
- };
- }
- }
- protected override void OnCalculate()
- {
- if (RefItem.State != ItemStates.Finished)
- return;
- PolyLineFeature feature = RefItem.GeoFeature;
- int width = 0;
- int height = 0;
- double UrmPhysicalwidth = 0;
- double UrmPhysicalheight = 0;
- NativeArray srcArray = new NativeArray(0);
- if (feature != null && feature.HostArea is ISRDicom && feature.HostArea.Mode is IDicomMode)//dicom回放
- {
- var dicomvisual = feature.HostArea as ISRDicom;
- bool isSRDen = dicomvisual.isSRDen();
- if (!isSRDen)
- return;
- var dicomdate = dicomvisual.GetSRDicomFile(ref width, ref height, ref UrmPhysicalwidth,
- ref UrmPhysicalheight);
- //todo 坐标转换
- srcArray.Resize(dicomdate.Length);
- Marshal.Copy(dicomdate, 0, srcArray.Start, dicomdate.Length);
- }
- else if (feature.HostArea.Mode is IModeWithURM)//在URM runing时测量
- {
- var modewithURM = feature.HostArea.Mode as IModeWithURM;
- if (modewithURM.URMStyle != "URM(Den)")
- return;
- var date = modewithURM.UrmArray;
- width = modewithURM.URMImgWidth;
- height = modewithURM.URMImgHeight;
- UrmPhysicalwidth = modewithURM.URMPhyWidth;
- UrmPhysicalheight = modewithURM.URMPhyHeight;
- srcArray.Resize(date.Length);
- Marshal.Copy(date, 0, srcArray.Start, date.Length);
- }
- else
- {
- return;
- }
- if (srcArray.Length != 8 * width * height)
- {
- _delayAction.BeginInvoke();
- return;
- }
- //todo 坐标转换
- double regionwidth = feature.HostArea.ViewPort.Region.Width;
- double regionheight = feature.HostArea.ViewPort.Region.Height;
- var points = RefItem.GeoFeature.Points;
- List<DPoint> ImagePoint = new List<DPoint>();
- for (int i = 0; i < points.Count; i++)
- {
- var point = SRPointTrans.TransPointS2I(points[i], regionwidth, regionheight,
- UrmPhysicalwidth, UrmPhysicalheight, width, height,false);
- if (point.X < 0 || point.X > width || point.X < 0 || point.X > width)
- continue;
- ImagePoint.Add(point);
- }
- if (ImagePoint.Count < 3)
- return;
- double pixelscaler = UrmPhysicalwidth / width;
- var urmcal = feature.HostArea.Mode as IURMCal;
- if (urmcal == null)
- return;
- var result = urmcal.GetURMShellDenMeasureResult(srcArray.Start, width, height, ImagePoint, RefItem.ShellWidth.Value / 10,
- pixelscaler, out var outshellPoints); //Todo OutShellPoint调用TransPointI2S转换为逻辑坐标用于绘制
- var transpoints = new List<DPoint>();
- foreach (var point in outshellPoints)
- {
- var transpoint = SRPointTrans.TransPointI2S(point, regionwidth, regionheight,
- UrmPhysicalwidth, UrmPhysicalheight, width, height);
- transpoints.Add(transpoint);
- }
- UpdateGeometry(transpoints);
- Outputs[0].UpdateDescription(Outputs[0].Name);
- feature.UpdateValue(Outputs[0], RoundValue(result.RoiDen * 100, GetResultDigits(PrimaryOutput)), Unit.percent);
- }
- protected void UpdateGeometry(List<DPoint> outResult)
- {
- var geometry = new TraceLineFeature(outResult, RefItem, RefItem.GeoFeature.XUnit,
- RefItem.GeoFeature.YUnit, false)
- {
- IsClosed = true,
- };
- if (RefItem.GeoFeature is ShellTraceFeature feature)
- {
- feature.UpdateChildFeatures(new List<GeometryFeature> { geometry });
- }
- }
- }
- }
- internal class URMShellVelMeasure : URMShellMeasure
- {
- public URMShellVelMeasure(ItemMeta meta, IMeasureItem parent = null)
- : base(meta, parent)
- {
- }
- internal static URMShellVelMeasure CreateURMShellVelMeasure(ItemMeta meta, IMeasureItem parent)
- {
- if (meta.BaseType != MeasureTypes.URMShellVelMeasure)
- {
- throw new ArgumentException();
- }
- meta.AddArgs(new MeasureParam(IsAutoSnapKey, "true", DefinitionPriorityEnum.Root));
- var item = new URMShellVelMeasure(meta, parent);
- item.Calculator = new URMShellVelMeasureCal(item);
- return item;
- }
- internal sealed class URMShellVelMeasureCal : Calculator<URMShellVelMeasure>
- {
- public URMShellVelMeasureCal(URMShellVelMeasure item)
- : base(item)
- {
- }
- public URMShellVelMeasureCal()
- {
- }
- protected internal override string[] SupportedOutputKeys
- {
- get
- {
- return new[]
- {
- MeasureTerms.URMVelMax, MeasureTerms.URMVelMin, MeasureTerms.URMVelMean, MeasureTerms.URMVelStd, MeasureTerms.Area,
- MeasureTerms.URMVelMaxIn, MeasureTerms.URMVelMinIn, MeasureTerms.URMVelMeanIn, MeasureTerms.URMVelStdIn, MeasureTerms.URMAreaIn,
- MeasureTerms.URMVelMaxOut, MeasureTerms.URMVelMinOut, MeasureTerms.URMVelMeanOut, MeasureTerms.URMVelStdOut, MeasureTerms.URMAreaOut,
- };
- }
- }
- protected override void OnCalculate()
- {
- if (RefItem.State != ItemStates.Finished)
- return;
- PolyLineFeature feature = RefItem.GeoFeature;
- int width = 0;
- int height = 0;
- double UrmPhysicalwidth = 0;
- double UrmPhysicalheight = 0;
- double UrmMinVel = 0;
- NativeArray srcArray = new NativeArray(0);
- if (feature != null && feature.HostArea is ISRDicom && feature.HostArea.Mode is IDicomMode)//dicom回放
- {
- var dicomvisual = feature.HostArea as ISRDicom;
- bool isSRVel = dicomvisual.isSRVel();
- if (!isSRVel)
- return;
- var dicomdate = dicomvisual.GetSRDicomFile(ref width, ref height, ref UrmPhysicalwidth,
- ref UrmPhysicalheight);
- //todo 坐标转换
- srcArray.Resize(dicomdate.Length);
- Marshal.Copy(dicomdate, 0, srcArray.Start, dicomdate.Length);
- UrmMinVel = dicomvisual.GetSRMinVel();
- }
- else if (feature.HostArea.Mode is IModeWithURM)//在URM runing时测量
- {
- var modewithURM = feature.HostArea.Mode as IModeWithURM;
- if (modewithURM.URMStyle != "URM(Vel)")
- return;
- var date = modewithURM.UrmArray;
- width = modewithURM.URMImgWidth;
- height = modewithURM.URMImgHeight;
- UrmPhysicalwidth = modewithURM.URMPhyWidth;
- UrmPhysicalheight = modewithURM.URMPhyHeight;
- UrmMinVel = modewithURM.URMMinVel;
- srcArray.Resize(date.Length);
- Marshal.Copy(date, 0, srcArray.Start, date.Length);
- }
- else
- {
- return;
- }
- //todo 坐标转换
- double regionwidth = feature.HostArea.ViewPort.Region.Width;
- double regionheight = feature.HostArea.ViewPort.Region.Height;
- var points = RefItem.GeoFeature.Points;
- List<DPoint> ImagePoint = new List<DPoint>();
- for (int i = 0; i < points.Count; i++)
- {
- var point = SRPointTrans.TransPointS2I(points[i], regionwidth, regionheight,
- UrmPhysicalwidth, UrmPhysicalheight, width, height,false);
- if (point.X < 0 || point.X > width || point.X < 0 || point.X > width)
- continue;
- ImagePoint.Add(point);
- }
- if(ImagePoint.Count<3)
- return;
- double pixelscaler = UrmPhysicalwidth / width;
- var urmcal = feature.HostArea.Mode as IURMCal;
- if (urmcal == null)
- return;
- var result = urmcal.GetURMShellVelMeasureResult(srcArray.Start, width, height, ImagePoint, RefItem.ShellWidth.Value/10,
- pixelscaler, out var outshellPoints); //Todo OutShellPoint调用TransPointI2S转换为逻辑坐标用于绘制
- var transpoints = new List<DPoint>();
- foreach (var point in outshellPoints)
- {
- var transpoint = SRPointTrans.TransPointI2S(point, regionwidth, regionheight,
- UrmPhysicalwidth, UrmPhysicalheight, width, height);
- transpoints.Add(transpoint);
- }
- UpdateGeometry(transpoints);
- foreach (var outputItem in Outputs)
- {
- outputItem.UpdateDescription(outputItem.Name);
- if (string.Equals(outputItem.Name, MeasureTerms.URMVelMax))
- {
- feature.UpdateValue(outputItem, RoundValue(result.MaxVel + UrmMinVel, outputItem), Unit.mms);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.URMVelMin))
- {
- feature.UpdateValue(outputItem, RoundValue(result.MinVel + UrmMinVel, outputItem), Unit.mms);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.URMVelMean))
- {
- feature.UpdateValue(outputItem, RoundValue(result.MeanVel + UrmMinVel, outputItem), Unit.mms);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.URMVelStd))
- {
- feature.UpdateValue(outputItem, RoundValue(Math.Sqrt(result.VarianceVel), outputItem), Unit.mms);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.Area))
- {
- feature.UpdateValue(outputItem, RoundValue(result.RoiArea, outputItem), Unit.cm2);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.URMVelMaxIn))
- {
- feature.UpdateValue(outputItem, RoundValue(result.InMaxVel + UrmMinVel, outputItem), Unit.mms);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.URMVelMinIn))
- {
- feature.UpdateValue(outputItem, RoundValue(result.InMinVel + UrmMinVel, outputItem), Unit.mms);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.URMVelMeanIn))
- {
- feature.UpdateValue(outputItem, RoundValue(result.InMeanVel + UrmMinVel, outputItem), Unit.mms);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.URMVelStdIn))
- {
- feature.UpdateValue(outputItem, RoundValue(Math.Sqrt(result.InVarianceVel), outputItem), Unit.mms);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.URMAreaIn))
- {
- feature.UpdateValue(outputItem, RoundValue(result.InRoiArea, outputItem), Unit.cm2);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.URMVelMaxOut))
- {
- feature.UpdateValue(outputItem, RoundValue(result.OutMaxVel + UrmMinVel, outputItem), Unit.mms);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.URMVelMinOut))
- {
- feature.UpdateValue(outputItem, RoundValue(result.OutMinVel + UrmMinVel, outputItem), Unit.mms);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.URMVelMeanOut))
- {
- feature.UpdateValue(outputItem, RoundValue(result.OutMeanVel + UrmMinVel, outputItem), Unit.mms);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.URMVelStdOut))
- {
- feature.UpdateValue(outputItem, RoundValue(Math.Sqrt(result.OutVarianceVel), outputItem), Unit.mms);
- }
- else if (string.Equals(outputItem.Name, MeasureTerms.URMAreaOut))
- {
- feature.UpdateValue(outputItem, RoundValue(result.OutRoiArea, outputItem), Unit.cm2);
- }
- }
- }
- private void UpdateGeometry(List<DPoint> outResult)
- {
- //if (outResult.ResultFlag)
- {
- //var resultPoints = outResult.OuterShellPoints;
- // var transformPoints = new List<DPoint>();
- // foreach (var point in outResult)
- // {
- // transformPoints.Add(RefItem.GeoFeature.HostArea.ViewPort.Convert(point));
- // }
- var geometry = new TraceLineFeature(outResult, RefItem, RefItem.GeoFeature.XUnit,
- RefItem.GeoFeature.YUnit, false)
- {
- IsClosed = true,
- };
- if (RefItem.GeoFeature is ShellTraceFeature feature)
- {
- feature.UpdateChildFeatures(new List<GeometryFeature> { geometry });
- }
- }
- }
- }
- }
- internal class SRTraceMeasure : Trace
- {
- private bool calflag = false;
- public SRTraceMeasure(ItemMeta meta, IMeasureItem parent = null)
- : base(meta, parent)
- {
- }
- internal static SRTraceMeasure CreateSRTraceMeasure(ItemMeta meta, IMeasureItem parent)
- {
- if (meta == null || meta.BaseType != MeasureTypes.SRTraceDensity)
- {
- throw new ArgumentException();
- }
- meta.AddArgs(new MeasureParam(IsAutoSnapKey, "true", DefinitionPriorityEnum.Root));
- var SRTrace = new SRTraceMeasure(meta, parent);
- SRTrace.Calculator = new SRTraceCal(SRTrace);
- return SRTrace;
- }
- public override void DownloadValueFromPreviousItem()
- {
- }
- protected override bool OnExecute(PointInfo args)
- {
- var cal = Calculator as SRTraceCal;
- if (args.VisualArea is ISRDicom)
- {
- var dicomvisual = args.VisualArea as ISRDicom;
- bool isSRDen = dicomvisual.isSRDen();
- if (args.VisualArea.Mode == null || !isSRDen)
- {
- return false;
- }
- }
- else
- {
- var modewithurm = args.VisualArea.Mode as IModeWithURM;
- if (modewithurm == null || modewithurm?.URMStyle != "URM(Den)")
- return false;
- }
- calflag = false;
- cal.calflag = false;
- var preState = State;
- var result = base.OnExecute(args);
- if (result && preState == ItemStates.Running && State == ItemStates.Finished)
- {
- calflag = true;
- cal.calflag = true;
- }
- return result;
- }
- protected override void OnExecuted(PointInfo args)
- {
- if (GeoFeature != null && Calculator != null && calflag)
- {
- Calculator.Calculate();
- }
- }
- internal sealed class SRTraceCal : Calculator<SRTraceMeasure>
- {
- public bool calflag = false;
- public SRTraceCal(SRTraceMeasure item)
- : base(item)
- {
- }
- public SRTraceCal()
- {
-
- }
- protected internal override string[] SupportedOutputKeys
- {
- get
- {
- return new[]
- {
- MeasureTerms.URMDenROI
- };
- }
- }
- protected override void OnCalculate()
- {
- if (!calflag)
- return;
- PolyLineFeature feature = RefItem.GeoFeature;
- int width = 0;
- int height = 0;
- double UrmPhysicalwidth = 0;
- double UrmPhysicalheight = 0;
- NativeArray srcArray = new NativeArray(0);
- if (feature != null && feature.HostArea is ISRDicom && feature.HostArea.Mode is IDicomMode)//dicom回放
- {
- var dicomvisual = feature.HostArea as ISRDicom;
- bool isSRDen = dicomvisual.isSRDen();
- if (!isSRDen)
- return;
- var dicomdate = dicomvisual.GetSRDicomFile(ref width, ref height, ref UrmPhysicalwidth,
- ref UrmPhysicalheight);
- //todo 坐标转换
- srcArray.Resize(dicomdate.Length);
- Marshal.Copy(dicomdate, 0, srcArray.Start, dicomdate.Length);
- }
- else if (feature.HostArea.Mode is IModeWithURM)//在URM runing时测量
- {
- var modewithURM = feature.HostArea.Mode as IModeWithURM;
- if (modewithURM.URMStyle != "URM(Den)")
- return;
- var date = modewithURM.UrmArray;
- width = modewithURM.URMImgWidth;
- height = modewithURM.URMImgHeight;
- UrmPhysicalwidth = modewithURM.URMPhyWidth;
- UrmPhysicalheight = modewithURM.URMPhyHeight;
- srcArray.Resize(date.Length);
- Marshal.Copy(date, 0, srcArray.Start, date.Length);
- }
- else
- {
- return;
- }
- if (srcArray.Length != 8 * width * height)
- {
- _delayAction.BeginInvoke();
- return;
- }
- //todo 坐标转换
- double regionwidth = feature.HostArea.ViewPort.Region.Width;
- double regionheight = feature.HostArea.ViewPort.Region.Height;
- var points = RefItem.GeoFeature.Points;
- List<DPoint> ImagePoint=new List<DPoint>();
- for (int i = 0; i < points.Count; i++)
- {
- var point= SRPointTrans.TransPointS2I(points[i], regionwidth, regionheight,
- UrmPhysicalwidth, UrmPhysicalheight, width, height);
- if (point.X < 0 || point.X > width || point.X < 0 || point.X > width)
- continue;
- ImagePoint.Add(point);
- }
- int outPointsNum = 0;
- var urmcal = feature.HostArea.Mode as IURMCal;
- if (urmcal == null|| ImagePoint.Count<3)
- return;
- double roivel = urmcal.GetSRTraceVel(srcArray.Start, width, height, ImagePoint);
- Outputs[0].UpdateDescription(Outputs[0].Name);
- feature.UpdateValue(Outputs[0], RoundValue(roivel * 100, GetResultDigits(PrimaryOutput)), Unit.percent);
- }
- }
- }
- internal class SRROIFractalDimMeasure : Rect
- {
- private bool calflag = false;
- public SRROIFractalDimMeasure(ItemMeta meta, IMeasureItem parent = null)
- : base(meta, parent)
- {
- }
- internal static SRROIFractalDimMeasure CreateSRROIFractalDimMeasure(ItemMeta meta, IMeasureItem parent)
- {
- if (meta == null || meta.BaseType != MeasureTypes.SRROIFractalDim)
- {
- throw new ArgumentException();
- }
- var SRROIFractalDim = new SRROIFractalDimMeasure(meta, parent);
- SRROIFractalDim.Calculator = new SRROIFractalDimCal(SRROIFractalDim);
- return SRROIFractalDim;
- }
- public override void DownloadValueFromPreviousItem()
- {
- }
- protected override bool OnExecute(PointInfo args)
- {
- var cal = Calculator as SRROIFractalDimCal;
- if (args.VisualArea is ISRDicom)
- {
- var dicomvisual = args.VisualArea as ISRDicom;
- bool isSRDen = dicomvisual.isSRDen();
- if (args.VisualArea.Mode == null || !isSRDen)
- {
- return false;
- }
- }
- else
- {
- var modewithurm = args.VisualArea.Mode as IModeWithURM;
- if (modewithurm == null || modewithurm?.URMStyle != "URM(Den)")
- return false;
- }
- calflag = false;
- cal.calfalg = false;
- var preState = State;
- var result = base.OnExecute(args);
- if (result && preState == ItemStates.Running && State == ItemStates.Finished)
- {
- calflag = true;
- cal.calfalg = true;
- }
- return result;
- }
- protected override void OnExecuted(PointInfo args)
- {
- if (GeoFeature != null && Calculator != null && calflag)
- {
- Calculator.Calculate();
- }
- }
- internal sealed class SRROIFractalDimCal : Calculator<SRROIFractalDimMeasure>
- {
- public bool calfalg = false;
- public SRROIFractalDimCal(SRROIFractalDimMeasure item)
- : base(item)
- {
- }
- public SRROIFractalDimCal()
- {
- }
- protected internal override string[] SupportedOutputKeys
- {
- get
- {
- return new[]
- {
- MeasureTerms.URMDenFractalDim
- };
- }
- }
- protected override void OnCalculate()
- {
- if(!calfalg)
- return;
- RectFeature feature = RefItem.GeoFeature;
- int width = 0;
- int height = 0;
- double UrmPhysicalwidth = 0;
- double UrmPhysicalheight = 0;
- NativeArray srcArray = new NativeArray(0);
- if (feature != null && feature.HostArea is ISRDicom && feature.HostArea.Mode is IDicomMode)//dicom回放
- {
- var dicomvisual = feature.HostArea as ISRDicom;
- bool isSRDen = dicomvisual.isSRDen();
- if (!isSRDen)
- return;
- var dicomdate = dicomvisual.GetSRDicomFile(ref width, ref height, ref UrmPhysicalwidth,
- ref UrmPhysicalheight);
- //todo 坐标转换
- srcArray.Resize(dicomdate.Length);
- Marshal.Copy(dicomdate, 0, srcArray.Start, dicomdate.Length);
- }
- else if (feature.HostArea.Mode is IModeWithURM)//在URM runing时测量
- {
- var modewithURM = feature.HostArea.Mode as IModeWithURM;
- if (modewithURM.URMStyle != "URM(Den)")
- return;
- var date = modewithURM.UrmArray;
- width = modewithURM.URMImgWidth;
- height = modewithURM.URMImgHeight;
- UrmPhysicalwidth = modewithURM.URMPhyWidth;
- UrmPhysicalheight = modewithURM.URMPhyHeight;
- srcArray.Resize(date.Length);
- Marshal.Copy(date, 0, srcArray.Start, date.Length);
- }
- else
- {
- return;
- }
- if (srcArray.Length != 8 * width * height)
- {
- _delayAction.BeginInvoke();
- return;
- }
- //todo 坐标转换
- double regionwidth = feature.HostArea.ViewPort.Region.Width;
- double regionheight = feature.HostArea.ViewPort.Region.Height;
- DPoint startDPoint = SRPointTrans.TransPointS2I(feature.TopLeft, regionwidth, regionheight,
- UrmPhysicalwidth, UrmPhysicalheight, width, height);
- DPoint endDPoint = SRPointTrans.TransPointS2I(feature.BottomRight, regionwidth, regionheight,
- UrmPhysicalwidth, UrmPhysicalheight, width, height);
- if (startDPoint.X < 0 || startDPoint.X > width || endDPoint.X < 0 || endDPoint.X > width
- || startDPoint.Y < 0 || startDPoint.Y > height || endDPoint.Y < 0 || endDPoint.Y > height)
- return;
- int outPointsNum = 0;
- var urmcal = feature.HostArea.Mode as IURMCal;
- if (urmcal == null)
- return;
- double FractalDimvel = urmcal.GetSRRoiFractalDim(srcArray.Start, width, height, startDPoint.X,
- startDPoint.Y, endDPoint.X, endDPoint.Y);
- Outputs[0].UpdateDescription(Outputs[0].Name);
- feature.UpdateValue(Outputs[0], RoundValue(FractalDimvel, GetResultDigits(PrimaryOutput)), Unit.None);
- }
- }
- }
- internal class SRROIVelMeasure : Rect
- {
- private bool calflag = false;
- public SRROIVelMeasure(ItemMeta meta, IMeasureItem parent = null)
- : base(meta, parent)
- {
- }
- internal static SRROIVelMeasure CreateSRROIVelMeasure(ItemMeta meta, IMeasureItem parent)
- {
- if (meta == null || meta.BaseType != MeasureTypes.SRRoiVel)
- {
- throw new ArgumentException();
- }
- var SRROIVel = new SRROIVelMeasure(meta, parent);
- SRROIVel.Calculator = new SRRolVelCal(SRROIVel);
- return SRROIVel;
- }
- public override void DownloadValueFromPreviousItem()
- {
- }
- protected override bool OnExecute(PointInfo args)
- {
- var cal = Calculator as SRRolVelCal;
- if (args.VisualArea is ISRDicom)
- {
- var dicomvisual = args.VisualArea as ISRDicom;
- bool isSrVel = dicomvisual.isSRVel();
- if (args.VisualArea.Mode == null || !isSrVel)
- {
- return false;
- }
- }
- else
- {
- var modewithurm = args.VisualArea.Mode as IModeWithURM;
- if (modewithurm == null || modewithurm?.URMStyle != "URM(Vel)")
- return false;
- }
- calflag = false;
- cal.calfalg = false;
- var preState = State;
- var result = base.OnExecute(args);
- if (result && preState == ItemStates.Running && State == ItemStates.Finished)
- {
- calflag = true;
- cal.calfalg = true;
- }
- return result;
- }
- protected override void OnExecuted(PointInfo args)
- {
- if (GeoFeature != null && Calculator != null && calflag)
- {
- Calculator.Calculate();
- }
- }
- internal sealed class SRRolVelCal : Calculator<SRROIVelMeasure>
- {
- public bool calfalg = false;
- public SRRolVelCal(SRROIVelMeasure item)
- : base(item)
- {
- }
- public SRRolVelCal()
- {
- }
- internal static readonly string SRkey = "SRRoiVel";
- protected internal override string[] SupportedOutputKeys
- {
- get { return new[] { SRkey }; }
- }
- protected override void OnCalculate()
- {
- if (!calfalg)
- return;
- RectFeature feature = RefItem.GeoFeature;
- int width = 0;
- int height = 0;
- double UrmPhysicalwidth = 0;
- double UrmPhysicalheight = 0;
- double UrmMinVel = 0;
- NativeArray srcArray = new NativeArray(0);
- if (feature != null && feature.HostArea is ISRDicom && feature.HostArea.Mode is IDicomMode)//dicom回放
- {
- var dicomvisual = feature.HostArea as ISRDicom;
- bool isSRVel = dicomvisual.isSRVel();
- if (!isSRVel)
- return;
- var dicomdate = dicomvisual.GetSRDicomFile(ref width, ref height, ref UrmPhysicalwidth,
- ref UrmPhysicalheight);
- //todo 坐标转换
- srcArray.Resize(dicomdate.Length);
- Marshal.Copy(dicomdate, 0, srcArray.Start, dicomdate.Length);
- UrmMinVel = dicomvisual.GetSRMinVel();
- }
- else if (feature.HostArea.Mode is IModeWithURM)//在URM runing时测量
- {
- var modewithURM = feature.HostArea.Mode as IModeWithURM;
- if (modewithURM.URMStyle != "URM(Vel)")
- return;
- var date = modewithURM.UrmArray;
- width = modewithURM.URMImgWidth;
- height = modewithURM.URMImgHeight;
- UrmPhysicalwidth = modewithURM.URMPhyWidth;
- UrmPhysicalheight = modewithURM.URMPhyHeight;
- UrmMinVel = modewithURM.URMMinVel;
- srcArray.Resize(date.Length);
- Marshal.Copy(date, 0, srcArray.Start, date.Length);
- }
- else
- {
- return;
- }
- //todo 坐标转换
- double regionwidth = feature.HostArea.ViewPort.Region.Width;
- double regionheight = feature.HostArea.ViewPort.Region.Height;
- DPoint startDPoint = SRPointTrans.TransPointS2I(feature.TopLeft, regionwidth, regionheight,
- UrmPhysicalwidth, UrmPhysicalheight, width, height);
- DPoint endDPoint = SRPointTrans.TransPointS2I(feature.BottomRight, regionwidth, regionheight,
- UrmPhysicalwidth, UrmPhysicalheight, width, height);
- if (startDPoint.X < 0 || startDPoint.X > width || endDPoint.X < 0 || endDPoint.X > width
- || startDPoint.Y < 0 || startDPoint.Y > height || endDPoint.Y < 0 || endDPoint.Y > height)
- return;
- var urmcal = feature.HostArea.Mode as IURMCal;
- if (urmcal == null)
- return;
- double meanSpeed = urmcal.GetSRRoiSpeed(srcArray.Start, width, height, startDPoint.X,
- startDPoint.Y, endDPoint.X, endDPoint.Y);
- meanSpeed += UrmMinVel;
- feature.UpdateValue(PrimaryOutput, RoundValue(meanSpeed, GetResultDigits(PrimaryOutput)), Unit.mms);
- }
- }
- }
- internal class SRTraceFractalDimMeasure : Trace
- {
- private bool calflag = false;
- public SRTraceFractalDimMeasure(ItemMeta meta, IMeasureItem parent = null)
- : base(meta, parent)
- {
- }
- internal static SRTraceFractalDimMeasure CreateSRTraceFractalDimMeasure(ItemMeta meta, IMeasureItem parent)
- {
- if (meta == null || meta.BaseType != MeasureTypes.SRTraceFractalDim)
- {
- throw new ArgumentException();
- }
- meta.AddArgs(new MeasureParam(IsAutoSnapKey, "true", DefinitionPriorityEnum.Root));
- var SRTraceFractalDim = new SRTraceFractalDimMeasure(meta, parent);
- SRTraceFractalDim.Calculator = new SRTraceFractalDimCal(SRTraceFractalDim);
- return SRTraceFractalDim;
- }
- public override void DownloadValueFromPreviousItem()
- {
- }
- protected override bool OnExecute(PointInfo args)
- {
- var cal = Calculator as SRTraceFractalDimCal;
- if (args.VisualArea is ISRDicom)
- {
- var dicomvisual = args.VisualArea as ISRDicom;
- bool isSRDen = dicomvisual.isSRDen();
- if (args.VisualArea.Mode == null || !isSRDen)
- {
- return false;
- }
- }
- else
- {
- var modewithurm = args.VisualArea.Mode as IModeWithURM;
- if (modewithurm == null || modewithurm?.URMStyle != "URM(Den)")
- return false;
- }
- calflag = false;
- cal.calflag = false;
- var preState = State;
- var result = base.OnExecute(args);
- if (result && preState == ItemStates.Running && State == ItemStates.Finished)
- {
- calflag = true;
- cal.calflag = true;
- }
- return result;
- }
- protected override void OnExecuted(PointInfo args)
- {
- if (GeoFeature != null && Calculator != null && calflag)
- {
- Calculator.Calculate();
- }
- }
- internal sealed class SRTraceFractalDimCal : Calculator<SRTraceFractalDimMeasure>
- {
- public bool calflag = false;
- public SRTraceFractalDimCal(SRTraceFractalDimMeasure item)
- : base(item)
- {
- }
- public SRTraceFractalDimCal()
- {
- }
- protected internal override string[] SupportedOutputKeys
- {
- get
- {
- return new[]
- {
- MeasureTerms.URMDenFractalDim
- };
- }
- }
- protected override void OnCalculate()
- {
- if (!calflag)
- return;
- PolyLineFeature feature = RefItem.GeoFeature;
- int width = 0;
- int height = 0;
- double UrmPhysicalwidth = 0;
- double UrmPhysicalheight = 0;
- NativeArray srcArray = new NativeArray(0);
- if (feature != null && feature.HostArea is ISRDicom && feature.HostArea.Mode is IDicomMode)//dicom回放
- {
- var dicomvisual = feature.HostArea as ISRDicom;
- bool isSRDen = dicomvisual.isSRDen();
- if (!isSRDen)
- return;
- var dicomdate = dicomvisual.GetSRDicomFile(ref width, ref height, ref UrmPhysicalwidth,
- ref UrmPhysicalheight);
- //todo 坐标转换
- srcArray.Resize(dicomdate.Length);
- Marshal.Copy(dicomdate, 0, srcArray.Start, dicomdate.Length);
- }
- else if (feature.HostArea.Mode is IModeWithURM)//在URM runing时测量
- {
- var modewithURM = feature.HostArea.Mode as IModeWithURM;
- if (modewithURM.URMStyle != "URM(Den)")
- return;
- var date = modewithURM.UrmArray;
- width = modewithURM.URMImgWidth;
- height = modewithURM.URMImgHeight;
- UrmPhysicalwidth = modewithURM.URMPhyWidth;
- UrmPhysicalheight = modewithURM.URMPhyHeight;
- srcArray.Resize(date.Length);
- Marshal.Copy(date, 0, srcArray.Start, date.Length);
- }
- else
- {
- return;
- }
- if (srcArray.Length != 8 * width * height)
- {
- _delayAction.BeginInvoke();
- return;
- }
- //todo 坐标转换
- double regionwidth = feature.HostArea.ViewPort.Region.Width;
- double regionheight = feature.HostArea.ViewPort.Region.Height;
- var points = RefItem.GeoFeature.Points;
- List<DPoint> ImagePoint = new List<DPoint>();
- for (int i = 0; i < points.Count; i++)
- {
- var point = SRPointTrans.TransPointS2I(points[i], regionwidth, regionheight,
- UrmPhysicalwidth, UrmPhysicalheight, width, height);
- if (point.X < 0 || point.X > width || point.X < 0 || point.X > width)
- continue;
- ImagePoint.Add(point);
- }
- int outPointsNum = 0;
- var urmcal = feature.HostArea.Mode as IURMCal;
- if (urmcal == null || ImagePoint.Count < 3)
- return;
- double roivel = urmcal.GetSRTraceFractalDim(srcArray.Start, width, height, ImagePoint);
- Outputs[0].UpdateDescription(Outputs[0].Name);
- feature.UpdateValue(Outputs[0], RoundValue(roivel, GetResultDigits(PrimaryOutput)), Unit.None);
- }
- }
- }
- public class SRVelMeasure : Location
- {
- internal SRVelMeasure(ItemMeta meta, IMeasureItem parent) :
- base(meta, parent, false)
- {
- }
- // Methods
- protected override bool OnExecute(PointInfo args)
- {
- if (args.VisualArea is ISRDicom)
- {
- var dicomvisual = args.VisualArea as ISRDicom;
- bool isSRVel = dicomvisual.isSRVel();
- if (args.VisualArea.Mode == null || !isSRVel)
- {
- return false;
- }
- }
- else
- {
- var modewithurm = args.VisualArea.Mode as IModeWithURM;
- if (modewithurm == null || modewithurm?.URMStyle != "URM(Vel)")
- return false;
- }
- return base.OnExecute(args);
- }
- internal static Location CreateSRVelMeasure(ItemMeta meta, IMeasureItem parent)
- {
- if (meta == null || meta.BaseType != MeasureTypes.SRLoactionVel)
- {
- throw new ArgumentException();
- }
- SRVelMeasure location = new SRVelMeasure(meta, parent);
- location.Calculator = new SRVelMeasure.SRVelCal(location);
- return location;
- }
- #region Nested Classes
- internal class SRVelCal : LocationCal, IGeoCalculator
- {
- #region Properties
- protected internal override string[] SupportedOutputKeys
- {
- get { return new[] { "SRVel" }; }
- }
- #endregion Properties
- #region Methods
- // Constructors
- internal SRVelCal(Location item)
- : base(item)
- {
- }
- protected internal SRVelCal()
- {
- }
- // Methods
- protected override void OnCalculate()
- {
- // throw new NotImplementedException();
- }
- public void Calculate(PointInfo pointInfo)
- {
- LocationFeature feature = RefItem.GeoFeature;
- int width = 0;
- int height = 0;
- double UrmPhysicalwidth = 0;
- double UrmPhysicalheight = 0;
- double UrmMinVel = 0;
- IntPtr buffer = new IntPtr();
- if (feature != null && feature.HostArea is ISRDicom && feature.HostArea.Mode is IDicomMode)
- {
- var dicomvisual = feature.HostArea as ISRDicom;
- bool isSRVel =dicomvisual.isSRVel();
- if (!isSRVel)
- return;
- var dicomdate = dicomvisual.GetSRDicomFile(ref width, ref height, ref UrmPhysicalwidth, ref UrmPhysicalheight);
- int size = dicomdate.Length;
- buffer = Marshal.AllocHGlobal(size);
- Marshal.Copy(dicomdate, 0, buffer, size);
- UrmMinVel = dicomvisual.GetSRMinVel();
- }
- else if(feature.HostArea.Mode is IModeWithURM)
- {
- var modewithurm = feature.HostArea.Mode as IModeWithURM;
- if(modewithurm.URMStyle!="URM(Vel)")
- return;
- var date = modewithurm.UrmArray;
- width = modewithurm.URMImgWidth;
- height = modewithurm.URMImgHeight;
- UrmPhysicalwidth = modewithurm.URMPhyWidth;
- UrmPhysicalheight = modewithurm.URMPhyHeight;
- UrmMinVel = modewithurm.URMMinVel;
- int size = date.Length;
- buffer = Marshal.AllocHGlobal(size);
- Marshal.Copy(date, 0, buffer, size);
- }
- else
- {
- return;
- }
- double regionwidth = feature.HostArea.ViewPort.Region.Width;
- double regionheight = feature.HostArea.ViewPort.Region.Height;
- DPoint curPoint = SRPointTrans.TransPointS2I(feature.Point, regionwidth, regionheight,
- UrmPhysicalwidth, UrmPhysicalheight, width, height);
- if (curPoint.X < 0 || curPoint.X > width || curPoint.Y < 0 || curPoint.Y > height)
- return;
- var curptr = buffer + sizeof(double) * ((int)curPoint.X + (int)curPoint.Y * width);
- double[] curvel = new double[1];
- Marshal.Copy(curptr, curvel, 0, 1);
- var velvalue = curvel[0];
- velvalue += UrmMinVel;
- if (velvalue < 0.01)
- velvalue = 0;
- feature.UpdateValue(PrimaryOutput, RoundValue(velvalue, GetResultDigits(PrimaryOutput)), Unit.mms);
- }
- #endregion Methods
- }
- #endregion Nested Classes
- }
- public class URMDen : ProtocolItem
- {
- internal URMDen(ItemMeta meta, IMeasureItem parent = null) : base(meta, true, parent)
- {
- }
- internal static URMDen Create(ItemMeta meta, IMeasureItem parent)
- {
- if (meta == null || meta.BaseType != MeasureTypes.URMDen)
- {
- throw new ArgumentException();
- }
- var item = new URMDen(meta, parent);
- item.Calculator = new URMDenCal(item);
- return item;
- }
- internal class URMDenCal : Calculator<URMDen>
- {
- protected internal override string[] SupportedOutputKeys => new[] { "URMDen" };
- public URMDenCal()
- {
- }
- public URMDenCal(URMDen item) : base(item)
- {
- }
- protected override void OnCalculate()
- {
- if (RefItem.Feature != null)
- {
- RefItem.Feature.Values.Clear();
- if (PrimaryOutput != null)
- {
- RefItem.Feature.UpdateValue(PrimaryOutput.Name, new StringValue(PrimaryOutput.Name) { Description = PrimaryOutput.Description });
- }
- }
- }
- }
- }
- public class URMVel : ProtocolItem
- {
- internal URMVel(ItemMeta meta, IMeasureItem parent = null) : base(meta, true, parent)
- {
- }
- internal static URMVel Create(ItemMeta meta, IMeasureItem parent)
- {
- if (meta == null || meta.BaseType != MeasureTypes.URMVel)
- {
- throw new ArgumentException();
- }
- var item = new URMVel(meta, parent);
- item.Calculator = new URMVelCal(item);
- return item;
- }
- internal class URMVelCal : Calculator<URMVel>
- {
- protected internal override string[] SupportedOutputKeys => new[] { "URMVel" };
- public URMVelCal()
- {
- }
- public URMVelCal(URMVel item):base(item)
- {
- }
- protected override void OnCalculate()
- {
- if (RefItem.Feature != null)
- {
- RefItem.Feature.Values.Clear();
- if (PrimaryOutput != null)
- {
- RefItem.Feature.UpdateValue(PrimaryOutput.Name, new StringValue(PrimaryOutput.Name) { Description = PrimaryOutput.Description});
- }
- }
- }
- }
- }
- public class FractalDimSR: URMDensityMeasure
- {
- internal FractalDimSR(ItemMeta meta, IMeasureItem parent = null) : base(meta, parent)
- {
- }
- internal static FractalDimSR CreateFractalDimSR(ItemMeta meta, IMeasureItem parent)
- {
- if (meta.BaseType != MeasureTypes.FractalDimSR)
- {
- throw new ArgumentException();
- }
- var item = new FractalDimSR(meta, parent);
- return item;
- }
- }
- public class DensitySR : URMDensityMeasure
- {
- internal DensitySR(ItemMeta meta, IMeasureItem parent = null) : base(meta, parent)
- {
- }
- internal static DensitySR CreateDensitySR(ItemMeta meta, IMeasureItem parent)
- {
- if (meta.BaseType != MeasureTypes.DensitySR)
- {
- throw new ArgumentException();
- }
- var item = new DensitySR(meta, parent);
- return item;
- }
- }
- public class URMDensityMeasure : MultiMethodItem
- {
- internal URMDensityMeasure(ItemMeta meta, IMeasureItem parent = null) : base(meta, parent)
- {
- }
- internal static URMDensityMeasure CreateURMDensityMeasure(ItemMeta meta, IMeasureItem parent)
- {
- if (meta.BaseType != MeasureTypes.URMDensityMeasure)
- {
- throw new ArgumentException();
- }
- var item = new URMDensityMeasure(meta, parent);
- return item;
- }
- }
- public class URMVelMeasure : URMDensityMeasure
- {
- internal URMVelMeasure(ItemMeta meta, IMeasureItem parent = null) : base(meta, parent)
- {
- }
- internal static URMVelMeasure CreateURMVelMeasure(ItemMeta meta, IMeasureItem parent)
- {
- if (meta.BaseType != MeasureTypes.URMVelMeasure)
- {
- throw new ArgumentException();
- }
- var item = new URMVelMeasure(meta, parent);
- return item;
- }
- }
- }
|